简体   繁体   中英

WCF service endpoint not accessible in self-hosting

I have created a IDummyService contract implemented by DummyService . I am trying to self-host this service using the following configuration:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
<system.serviceModel>
    <services>
      <service name="DummyService.DummyService" behaviorConfiguration="MEX">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/" />
          </baseAddresses>
        </host>
        <endpoint address="DummyService" 
                  binding="basicHttpBinding" 
                  contract="DummyService.IDummyService"/>
        <endpoint address="net.tcp://localhost:8734/DummyService/" 
                  binding="netTcpBinding" 
                  bindingConfiguration = "TransactionalTCP" 
                  contract="DummyService.IDummyService"/>
        <endpoint address="mex" binding="mexHttpBinding"    contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name = "TransactionalTCP" transactionFlow = "true"/>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name = "MEX">
          <serviceMetadata/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

The Service Host code that runs fine and starts these endpoints. However, when I try to access the following endpoints I get error as Page isn't working in Chrome browser.

http://localhost:8733/DummyService/
http://localhost:8733/mex/

However, I can access the page http://localhost:8733/

I don't understand why is that.

I thought the endpoint address is address entry for that endpoint appended to host's baseaddress

Any ideas what I am doing wrong ?

Thanks.

You have applied the attribute behaviorConfiguration="MEX" but didnt make use of it,you need to enable the metadata discovery which is false by default in WCF for security reasons.

<serviceBehaviors>
        <behavior name = "MEX">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>

Now when you browse the http://localhost:8733/DummyService/ and http://localhost:8733/mex/ ,a blank page will be displayed in the browser,instead of default error page.

And also if you want to test the net.tcp endpoint you can use WCFtestclient.exe.

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