【问题标题】:WCF service endpoint not accessible in self-hosting在自托管中无法访问 WCF 服务端点
【发布时间】:2018-01-08 13:46:44
【问题描述】:

我创建了一个由DummyService 实现的IDummyService 合约。我正在尝试使用以下配置self-host此服务:

<?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>

运行良好并启动这些端点的服务主机代码。但是,当我尝试访问以下端点时,我在 Chrome 浏览器中收到 Page isn't working 错误。

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

但是,我可以访问页面http://localhost:8733/

我不明白为什么会这样。

我认为端点地址是附加到主机 baseaddress 的端点的 address 条目

任何想法我做错了什么?

谢谢。

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    您已应用属性 behaviorConfiguration="MEX" 但没有使用它,出于安全原因,您需要启用 WCF 中默认为 false 的元数据发现。

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

    现在当您浏览http://localhost:8733/DummyService/和http://localhost:8733/mex/时,浏览器中会显示一个空白页面,而不是默认的错误页面。

    如果你想测试 net.tcp 端点,你可以使用 WCFtestclient.exe。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多