【问题标题】:Host WCF service in WAS在 WAS 中托管 WCF 服务
【发布时间】:2011-12-05 17:45:15
【问题描述】:

我需要一些关于在 WAS 中托管 WCF 服务的帮助。 我在 IIS 中托管了该服务,并通过 basicHttp 和 wsHttp 绑定进行访问。 但是,当我尝试在 WAS 中托管它并通过 tcp/ip 访问时,我似乎错过了一些东西。

我需要将其配置为通过端口 10000 上的 tcp 访问。

我在 Windows 功能中为非 HTTP 启用了 WCF 激活

服务发布在默认网站,应用程序 mywcfapp

我创建了一个 BAT 文件以在默认网站和 mywcfapp 的端口 10000 上启用 net.tcp 绑定,如下所示:

%windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.tcp',bindingInformation='10000:*']
%windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/mywcfapp" /enabledProtocols:http,net.tcp

web.config 是

<services>
  <service name="MyWcfService">
    <clear />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
      listenUriMode="Explicit" />

    <endpoint address="net.tcp://localhost:10000/mywcfapp/mywcfapp.svc"
      binding="netTcpBinding" bindingConfiguration="PortSharingBinding" contract="MyApp.IService" />
    <endpoint address="net.tcp://localhost:10000/mywcfapp/mywcfapp.svc"
      binding="netTcpBinding" bindingConfiguration="PortSharingBinding" contract="MyApp.IService" />

  </service>
</services>

<bindings>
  <netTcpBinding>
    <binding name="PortSharingBinding" portSharingEnabled="true">
      <security mode="None" />
    </binding>
  </netTcpBinding>
</bindings>

但是,我似乎无法访问该服务。

当我尝试使用带有 uri 的 WcfTestClient 访问服务时

net.tcp://localhost:10000/mywcfapp/mywcfapp.svc/mex

我收到以下错误

<Fault xmlns="http://www.w3.org/2003/05/soap-envelope">
<Code>
    <Value>Sender</Value>
    <Subcode><Value xmlns:a="http://www.w3.org/2005/08/addressing">a:DestinationUnreachable</Value>
    </Subcode>
</Code>
<Reason><Text xml:lang="ro-RO">
    The message with To 'net.tcp://localhost:10000/mywcfapp/mywcfapp.svc/mex' 
    cannot be processed at the receiver, due to an AddressFilter mismatch 
    at the EndpointDispatcher.  
    Check that the sender and receiver's EndpointAddresses agree.
</Text></Reason>
</Fault>

如果我尝试使用 url 连接(不指定端口)

net.tcp://localhost/OneTest.Service/OneTest.Service.svc/mex

我得到了错误(只保留重要部分)

Could not connect to net.tcp://localhost/mywcfapp/mywcfapp.svc/mex. 
The connection attempt lasted for a time span of 00:00:02.0041146. 
TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:808.     
No connection could be made because the target machine actively refused it 127.0.0.1:808

【问题讨论】:

    标签: wcf wcf-binding was


    【解决方案1】:

    这可能会有所帮助:

    转到 IIS 管理器。 右键单击应用程序。 选择管理应用程序 -> 高级设置 在 Behavior 下,有一个 Enabled Protocols 字段。

    确保它有net.tcp

    如果只有http,则改为

    http,net.tcp
    

    【讨论】:

    • 谢谢,我检查了一下,它已经启用(我想我在运行 BAT 时启用了它)。但是,我怀疑问题出在端口的某个地方。奇怪的是,如果我在 WCF 测试客户端的 URI 中包含端口(10000),则错误是 EndpointDispatcher 的 AddressFilter 不匹配。如果我在 URI 中不包含端口,似乎客户端正在尝试连接到端口 808 上的服务器,但为什么呢?
    • 确保http和net.tcp之间没有空格,只有逗号。
    猜你喜欢
    • 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
    相关资源
    最近更新 更多