简体   繁体   中英

WCF client cannot connect to WCF service hosted in IIS via ServiceHost?

I have this scheme:

IIS

  • hosts: OperatorService.svc (connects to ClientService )
  • Global.asax (on start): hosts ClientService via ServiceHost

WPF client

  • connects to ClientService


If I go to OperatorService the service is activated, web application started, and ClientService is successfully hosted at http://localhost:8020/ClientService . So far so good.

I can now access the ClientService in the aforementioned URL in a browser, I can add it through Add Service Reference . It's simply there - running.

But when I try to connect via generated client (looks OK), it suddenly doesn't work. Throwing:

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

Moreover the OperatorService connects to this ClientService itself (it is a WsDualHttpBinding to provide notifications). It subscribes itself correctly to this service (calling a method) and it works (same URL as my WPF client).

Why can't I connect from my WPF client?

WPF client config (only relevant sections):

<client>
    <endpoint address="http://localhost:8020/ClientService" binding="wsDualHttpBinding"
        bindingConfiguration="DefaultBindingClientService" contract="Server.IClientService"
        name="DefaultBindingClientService">
        <identity>
            <servicePrincipalName value="host/OHS-UPC" />
        </identity>
    </endpoint>
</client>
<bindings>
    <wsDualHttpBinding>
        <binding name="DefaultBindingClientService" />
    </wsDualHttpBinding>
</bindings>

IIS hosted web.config (for ClientService )

<service name="TelPro.OHS.Server.Services.ClientService" behaviorConfiguration="UnsecuredBehavior">
    <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="DefaultBindingClientService" contract="TelPro.OHS.Server.Services.IClientService"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    <host>
        <baseAddresses>
            <add baseAddress="http://localhost:8020/ClientService"/>
        </baseAddresses>
    </host>
</service>

<wsDualHttpBinding>
    <binding name="DefaultBindingClientService"/>
</wsDualHttpBinding>

<behavior name="UnsecuredBehavior">
    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
    <serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>

IIS hosted web.config (for OperatorService -> ClientService)

<client>
    <endpoint address="http://localhost:8020/ClientService" binding="wsDualHttpBinding" 
        bindingConfiguration="DefaultBindingClientService" contract="ClientNotificationServer.IClientService" 
        name="DefaultBindingClientService" />
</client>

<wsDualHttpBinding>
    <binding name="DefaultBindingClientService" />
</wsDualHttpBinding>

I was able to solve it by switching to port 80.

http://localhost/ClientService

Somehow that works. I've tried to add rules to port 8020 everywhere (even stopped firewall), checked any port forwarding, Azure endpoints, etc. My theory is that the problem when server is trying to connect back (callback) to client and has no rights or something. My guess would be that IIS hosted service doesn't have enough rights to connect back. If anyone can still shed some light on the why, I would gladly switch answer to them. But so far I'm just glad it works regardless the port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM