WCF NetTcpBinding with mex

16

我正在尝试使用nettcpbinding发布WCF服务。我希望发布元数据, 并使用 ?wsdl。我将以下行添加到配置文件中:

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

但是我无法在浏览器中看到wsdl。我做错了什么吗? 谢谢。

编辑:这是我配置文件中相关的部分:

<system.serviceModel>
   <services>
<service name="wcfcheck.service1" behaviorConfiguration="wcfcheck.Service1Behavior">
       <endpoint address="" binding="netTcpBinding" contract="wcfcheck.Iservice1"/>
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
   </services>
<behaviors>
<serviceBehaviors>
  <behavior name="wcfcheck.Service1Behavior">
    <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
    <serviceDebug includeExceptionDetailInFaults="true"/>
  </behavior>
</serviceBehaviors>

我可能没有访问正确的URL。我尝试了http://localhost:51159/Service1.svc?wsdlhttp://localhost:51159/Service1.svc/mex?wsdl,以及没有带“?wsdl”参数的URL。


你在基地址方面定义了什么?我在你的配置中没有看到任何内容...你只为MEX端点设置了address="mex",但那不是完整的地址。 - marc_s
你需要拥有一个可以找到MEX的http://基础地址,或者在<serviceMetadata>标签中实际指定一个“httpGetUrl”。 - marc_s
无论我将baseaddress或httpGetUrl写成什么样子,都似乎不起作用。例如:http://localhost:51159/mex 或 http://localhost:51159/service1.svc 或 http://localhost:51159/service1.svc/mex 或添加 ?wsdl 都没有效果。请帮帮忙! - Clangon
3个回答

13
你需要使用 <serviceMetadata> 元素。
    <behaviors>
      <serviceBehaviors>
      <behavior name="metadataSupport">
        <!-- Enables the IMetadataExchange endpoint in services that -->
        <!-- use "metadataSupport" in their behaviorConfiguration attribute. -->
        <!-- In addition, the httpGetEnabled and httpGetUrl attributes publish -->
        <!-- Service metadata for retrieval by HTTP/GET at the address -->
        <!-- "http://localhost:8080/SampleService?wsdl" -->
        <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
      </behavior>
    </serviceBehaviors>
  </behaviors>

12

您需要通过HTTP发布服务元数据以获取WSDL。将以下标签添加到配置文件的<system.serviceModel>标记中。

<behaviors>
  <serviceBehaviors>
    <behavior name = "MetadataBehavior">
      <serviceMetadata httpGetEnabled = "true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

您还需要指定一个HTTP地址,在那里wsdl中的服务元数据可用。将此添加到配置文件的<service>节点中:

<host>
  <baseAddresses>
    <add baseAddress="net.tcp://localhost:8001" />
    <add baseAddress="http://localhost:8000/Service1" />
  </baseAddresses>
</host>

如果你访问http://localhost:8000/Service1?wsdl,那么你应该可以看到你的服务的WSDL文件。


2
主机标签应该放在哪个部分? - Maslow
@Maslow https://learn.microsoft.com/zh-cn/dotnet/framework/configure-apps/file-schema/wcf/baseaddresses - RB.

1
你可以尝试使用mexTcp绑定,并确保你的基地址以net.tcp://开头.....

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接