We have a custom WebPart solution (SharePoint 2013 SP1) that needs to communicate with a Web Service that is not located on our SharePoint farm. I went through the regular motions of adding a Service Reference (Visual Studio -> Service References -> Add Service Reference...) in the project. I ultimately had two services I needed to add so I ended up with the following in my app.config file.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SecurityTransport">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://myurl/cgi-bin/jsmdirect?authentication"
binding="basicHttpBinding" bindingConfiguration="SecurityTransport"
contract="Dev.Foo.AuthenticationServerService.AuthenticationServerServicePortType"
name="AuthenticationServerServicePort" />
<endpoint address="https://myurl2/cgi-bin/jsmdirect?authentication"
binding="basicHttpBinding" bindingConfiguration="SecurityTransport"
contract="Prd.Foo.AuthenticationServerService.AuthenticationServerServicePortType"
name="AuthenticationServerServicePort1" />
</client>
</system.serviceModel>
</configuration>
I also verified that the deployment process was adding this in the Web.config files for our Web Applications. There the serviceModel looks like the following:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="SecureTransport">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://myurl/cgi-bin/jsmdirect?authentication" binding="basicHttpBinding" bindingConfiguration="SecureTransport" contract="Dev.Foo.AuthenticationServerService.AuthenticationServerServicePortType" name="AuthenticationServerServicePort" />
<endpoint address="https://myurl2/cgi-bin/jsmdirect?authentication" binding="basicHttpBinding" bindingConfiguration="SecureTransport" contract="Prd.Foo.AuthenticationServerService.AuthenticationServerServicePortType" name="AuthenticationServerServicePort1" />
</client>
</system.serviceModel>
I even added the serviceModel changes to the overall Hive web.config just to be sure during testing. Though I have removed it since. Regardless of what changes I make or if I do an IISRESET after the fact I continue to get the following error message when the service client is instantiated.
System.InvalidOperationException: Could not find default endpoint element that references contract 'Dev.Foo.AuthenticationServerService.AuthenticationServerServicePortType' 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.
I have seen several solutions online now that recommend copying the serviceModel information into the Web Configs which you can see I have done. I saw some troubleshooting where they recommend hitting the service outside of the application but from those servers to confirm connectivity which I have also done successfully.
I have seen other more complex suggestions which recommend avoiding the Web.config all together (e.g., https://stackoverflow.com/questions/54579/wcf-configuration-without-a-config-file) and handling your bindings and endpoints programmatic but I cannot seem to grasp where the MyServiceSoapClient object is coming from in that suggestion. The service I am hitting is not a WCF service so I cannot simply build a client for it that hands it a "binding, new EndpointAddress( "http://www.mysite.com/MyService.asmx" )" as is recommended in that link. Plus I would rather avoid this work around and just get this to work as was intended via the Web.config.
Help!?!?