0
votes

I am consuming a WCF Service from a webpart in Sharepoint 2007. But its giving me the following error:

There was no endpoint listening at http://locathost:2929/BusinessObjectService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: The remote server returned an error: (404) Not Found.

My Binding Details in the WCF web.config is:

<system.serviceModel>
    <diagnostics performanceCounters="All">
      <messageLogging logEntireMessage="true" logMessagesAtServiceLevel="false"
        maxMessagesToLog="4000" />
    </diagnostics>
    <services>
      <service behaviorConfiguration="MyService.IBusinessObjectServiceContractBehavior"
        name="MyService.BusinessObjectService">
        <endpoint address="http://localhost:2929/BusinessObjectService.svc"
          binding="wsHttpBinding" contract="MyService.IBusinessObjectServiceContract">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyService.IBusinessObjectServiceContractBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

My binding details in the Sharepoint site web.config is:

<system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IBusinessObjectServiceContract"
                    closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
                    sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false"
                    hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
                    maxReceivedMessageSize="65536" messageEncoding="Mtom" textEncoding="utf-8"
                    useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
          <security mode="Message">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
                algorithmSuite="Default" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:2929/BusinessObjectService.svc"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IBusinessObjectServiceContract"
          contract="BusinessObjectService.IBusinessObjectServiceContract"
          name="WSHttpBinding_IBusinessObjectServiceContract">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

I am able to view the WCF (and its wsdl) in browser, using the URL given in the end point. So, I guess the URL is definately correct. Please help !!!

2
Are you able to try without the identity elements? This means first getting things to work unsecured, and then applying security later. - Kirk Broadhurst
Yes, but not change..... - Bhaskar
are they on the same machine? if not then you have a problem for using localhost on the endpoint address. - Jojo Sardez
Yes...they are in the same machine....same IIS - Bhaskar

2 Answers

1
votes

I've replicated your code and it runs correctly for me, but there are a couple of discrepencies.

Firstly, the server side configuration you've supplied is not complete. The endpoint mex fails because I don't have the IMetadataExchange contract. When you browse to the WSDL, this is presumably the endpoint you are viewing.

I'm just removing this endpoint altogether. Following from this, I'm specifying an address for the serviceMetadata element in the behavior like this:

<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:2929/BusinessObjectService.svc?wsdl" />

Not ideal but it works to let me discover the service. Then my generated client config file is the same as yours, except...

Secondly, I have messageEncoding="Text" instead of messageEncoding="Mtom"

Try changing messagingEncoding to Text. You haven't specified on server side that it should be Mtom so I don't understand why it has been generated on client side as Mtom.

Apart from these two issues my configuration is the same as yours, and it runs without a problem. I'm not sure that the second issue I've identified is a real issue at all (I can't see how the metadata exchange would give the wrong message encoding), but the first issue is stopping the service from running on my side.

0
votes

I got an error that looked almost identical as the described error. However my error was a 503 and I was calling a web service on an external server.

When I called the service from a standalone app I had no problems, but when I called the service from a web part in SharePoint it failed.

Solutions that worked me, without any further explanation because I haven't really digged into why it works (If you know, please enlighten me :))

1st solution that worked for me was to use my own domain account instead of the service account for the application pool that was used by the SPWebApplication.

2nd solution was to set the service binding attribute UseDefaultWebProxy to false

UseDefaultWebProxy = false

Of course these solutions depends on your proxy settings and user settings. My proxy settings was setup to bypass proxy for the service I was calling, so my suspicion is that the proxy settings (configured here: IE->Internet Options->Connections->LAN settings) doesn't apply to the service account but only to the logged in user. By now, this is what I'll investigate more.

EDIT 1: Hmm. that was actually not bringing anything new to the table, I used psexec to view my proxy settings as the service account (netsh->winhttp->show proxy) and that looked correct, so I don't think this could be the issue.

EDIT 2: Final solution, so the problem was that my SP web app was not using the proxy settings I had setup in IE when the app pool was run in the context of a service account, when I used my user account for the app pool I had no problems and the proxy settings in IE was used. After a little more investigation it appeared that I could define proxy settings for my SPWebApplication in web.config and I chose just to disable the proxy

<system.net> <defaultProxy enabled="false" /> </system.net>