A web site code can't connect to a soap servic

2019-02-20 00:31发布

问题:

My ASP.NET web site calls a .net service from a code in App_Code to retrieve some information.

The web service is hosted at http://mydomain/ws/DirectoryService.asmx.

Whenever I deploy a web site on any server other then the same server that the required .net service is hosted on, everything works good.

Whenever I deploy the site to the same web server, that the web service is hosted on, I get 401.1 error.

I have the following binding defined in web.config of the site:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="LR Directory ServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://mydomain/ws/DirectoryService.asmx" binding="basicHttpBinding" bindingConfiguration="LR Directory ServiceSoap" contract="ExpertsServiceReference.LRDirectoryServiceSoap" name="LR Directory ServiceSoap" />
    </client>
  </system.serviceModel>

Apparently, the problem lies in that binding. It can't work from within the same server. How can the problem be fixed?

P.S. If I comment out the binding in web.config, the web site loads fine, but it is not fully functional, since it can't connect to a service.

UPDATE: A very important detail: My target web site and a .net service are both located on the same server, same IIS, but are bound to a different external IP addresses, so the problem can't be in a network access field.

Also, If I set the authentication mode of the web site from Anonymous to Windows, everything works fine, but I need to provide a windows creds each time I access the site.

回答1:

Problem solved. It turned out that I needed to Edit an anonymous authentication settings, so that when used (in my case it is always), the code would go under application pool's identity, and not IUSR:



回答2:

Ensure you are running the webservice and website on different ports, and make sure your configuration reflects the correct port.

If you are running two websites on the same port (by default this would be port 80, reserved for HTTP), they will conflict with each other - one of them will get the port, the other will not.

Say you change the web service port to 8080, you would configure the site to use the endpoint:

address="http://mydomain:8080/ws/DirectoryService.asmx"