I have created WCF Service and trying to consume it in a Sharepoint web part. It is giving following error while deploying web part :
"could not find default endpoint element that references contract 'ServiceRe开发者_JAVA技巧ference1.IService1' in the ServiceModel client configuration section"
Any help would be appreciated
How do you consume it? In case you created an app.config for your webpart, that won't work as web part are executed in the context of the w3wp.exe process.
You have to either manually setup the endpoints in your Service Client, or put it in the web.config of the Sharepoint Virtual Directory (c:\inetpub\wwwroot\wss\80 I think). If you have multiple servers, add it to all. (I would recommend creating a feature receiver that modifies the web.config, but I learned the hard way that SPWebConfigModification should never ever be used)
Programmatically setting up the Client:
var endpoint = new EndpointAddress(new Uri("http://your/wcf/endpoint"));
var binding = new WSHttpBinding();
var client = new YourWCFClient(binding, endpoint);
The exact binding depends on your configuration of course - WCF is a bit tricky here, but if you have a working client already, check it's app.config for the binding info and MSDN for the classes that derive from System.ServiceModel.Channels.Binding to find the correct one.
Micheal Stu8om is correct. You need to copy and paste the content of the system. serviceModel tag from your webpart config file in to the SharePoint web.confi located in the root of the SharePoint deployment (the last bit of path in Michael's post is not always 80. It maybe 443 or something else depending on the SharePoint deployment port).
I would like to reommend reading chapter 5 of Sahil Malik book "Building solutions for SharePoint 2010". Hope this helps
精彩评论