Search code examples
wcfiiswcf-endpoint

"There was no endpoint listening at" issue with a IIS Hosted WCF Service consuming another web service


I have created a WCF service which is hosted in IIS and that tries to call another web service (3rd party) to return some data. When trying to connect the service fails with the following error:

There was no endpoint listening at https://xxx (3rd party ws) that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

And this is while, my service is up (i know from my echo method) and it works successfully if it is self hosted.

I have the whole and sections copied to the model of web.config exactly as it is for the self hosting test but something still is missing.

I have been through other similar problems reported but mine is little bit specific in that the service is kind-of hosting another one and that one is causing the issue.

I can try to exlain better with a real example:

There is a simple web service here: http://www.dneonline.com/calculator.asmx which I want to wrap inside our library and provide access to via an IIS hosted WCF. So, a class library is created (Calculator project) to with one method, add to take two int arguments and use them to call the web service add method. The webservice is referenced as a Service Reference inside the library and is being addressed inside from within the config library app.config file like below:

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="CalculatorSoap" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://www.dneonline.com/calculator.asmx"
                binding="basicHttpBinding" bindingConfiguration="CalculatorSoap"
                contract="Service.CalculatorSoap" name="CalculatorSoap" />
        </client>
    </system.serviceModel>
</configuration>

Then there is a WCF class library (CalcService project) which uses the first class library to enable http endpoints. Again, the app.config file includes endpoints both as for the service itself and as a client of the class library. The app.config file looks almost like this:

<configuration>
  <system.serviceModel>
    <services>
      <service name="CalcService.Calc">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/CalcService/Calc/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <endpoint address="" binding="basicHttpBinding" contract="CalcService.ICalc">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <!-- Client endpoint, i.e. to be able to use the calculator.asmx service addressed in the class library -->
    <client>  
      <endpoint address="http://www.dneonline.com/calculator.asmx"
          binding="basicHttpBinding"
          contract="Service.CalculatorSoap" name="CalculatorSoap" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

I am able to test the whole thing via a console application that makes a call to the WCF service and receives an answer. The console application config file has only one client endpoint to the WCF like below:

<configuration>
  <system.serviceModel>
    <client>
      <endpoint address="http://localhost:8733/Design_Time_Addresses/CalcService/Calc/"
             binding="basicHttpBinding" contract="Calculator.ICalc" name="BasicHttpBinding_ICalc" />
    </client>
  </system.serviceModel>
</configuration>

My question is now how I can host the WCF service inside IIS? I have tried different ways but neither one worked. My current IIS project (which doen't work) looks like this: 1-Has project references to both prevoius projects (Class Library and WCF Service) so two dll files are being added to the references:

  • CalcService.dll
  • Calculator.dll

2-Has a CalcService.svc file which creates a ServiceHost toward the CalcService: <%@ ServiceHost Language="C#" Debug="true" Service="CalcService.Calc"%>

3-Has a web.config with cliend endpoint to calculator.asmx:

 <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="CalculatorSoap" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://www.dneonline.com/calculator.asmx"
            binding="basicHttpBinding" bindingConfiguration="CalculatorSoap"
            contract="Service.CalculatorSoap" name="CalculatorSoap" />
    </client>
    <!-- some other settings -->    
</system.serviceModel>

Now, when tested with a simple client to make a call to the calculator add method it fails with the following error:

There was no endpoint listening at http://www.dneonline.com/calculator.asmx that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

I don't know which message the endpoint is expecting, I could just assumed it has to be Service.CalculatorSoap as it worked before from the console application. On the other hand, what confuses me is that a self hosted WCF also works (via http://localhost:8733/Design_Time_Addresses/CalcService/Calc/ from the config file in the WCF class library project). I don't know what is missing here, is it something from the IIS configuration or permissions? Or someting else like the windows firewall setting like explained in this post:

Just note that since I am using a company computer, I'm not able to shut down the firewall. I can just turn on/off some of the rules.

I hope it is clear now what we are after.


Solution

  • We tested the solution on a cloud based machine and it worked fine. In the end it looked to be some firewall rules blocking the IIS outgoing calls and nothing was wrong in the configuration files or in the code.