1

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!?!?

1

We solved this problem by not using Visual Studio's regular Service Reference being added. Instead we added a Web Reference (as explained here, http://msdn.microsoft.com/en-us/library/bb628649.aspx). Essentially you do the following:

To add a Web reference to a project

  1. In Solution Explorer, right-click the name of the project that you want to add the service to, and then click Add Service Reference. The Add Service Reference dialog box appears. In the Add Service Reference dialog box, click the Advanced button. The Service Reference Settings dialog box appears.
  2. In the Service Reference Settings dialog box, click Add Web Reference. The Add Web Reference dialog box appears.
  3. In the URL box, enter the URL of the Web service to use. If you do not know the URL, use the links in the browse pane to locate the Web service you want. Note If you are developing a Web application on a computer that is behind a firewall, and your application will consume Web services from outside the firewall, you must include the address and port of your network's proxy server in the URL. Ask your network administrator to furnish this part of the URL path. For more information, see The proxy settings on this computer are not configured correctly for Web discovery.
  4. In the Web services found at this URL box, select the Web service to use.
  5. Verify that your project can use the Web service, and that any external code provided is trustworthy. Note When you open a project for editing that includes a Web reference, a local proxy file for the Web service consumed runs in a process of Devenv.exe started by a trusted user, yourself. Opening projects or components in the integrated development environment (IDE) can execute code on the local computer. For more information, see Code Access Security.
  6. In the Web reference name field, enter a name that you will use in your code to access the selected Web service programmatically. Note By default, Web references are assigned a namespace that corresponds to their server name. You can change this value and enter a custom namespace name. There are some limitations on acceptable namespace names. For more information about characters that are not allowed in a Web reference name, see Add Web Reference Dialog Box. A namespace based on the Web reference name is created by building a nested folder hierarchy. Inside the innermost folder, a .wsdl file that references the Web service is created, together with supporting files, such as discovery (.disco and .discomap) files, that include information about where the Web service is located.
  7. Click Add Reference. If your project site does not already have one, Visual Studio creates a WebReferences folder. It then creates files that are required for the proxy class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.