I am working on a SharePoint 2013 webpart and a label on the webpart needs to communicate with a SQL Server data table using WCF. I have created the WCF interface and main class, and have also invoked the service in my Visual webpart like this:
protected void Page_Load(object sender, EventArgs e)
{
WcfServiceReference1.Service1Client client = new WcfServiceReference1.Service1Client();
CustomerNameLbl.Text = client.GetCustomerName(ProjectIDDescLbl.Text);
}
Where WcfServiceReference1 is the added WCF service reference and a customer label text is being changed depending on the project number label. The project builds and deploys fine but when I add the webpart, I get this error: Could not find default endpoint element that references contract 'WcfServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
My app.config file is this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://as-sv-dev02:2345/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
And web.config file (for SharePoint) is this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://as-sv-dev02:2345/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
Can anyone guide me on how to resolve this? Am I going wrong somewhere?
http://as-sv-dev02:2345/Service1.svc
in a browser, what do you see? – Tim