Can';t为托管在IIS中的netTcpBinding的WCF服务添加服务引用
对于已部署到IIS的服务,我有以下配置。我可以使用URL将该服务的服务引用添加到wsHttpBinding端点,但无法使用URL将其添加到mexHttpBinding端点(我希望将客户端切换为使用netTcpBinding) 我得到的错误是: 下载“”时出错http://ServerName:98/MyService.svc/mex" 请求失败,HTTP状态为400:请求错误 元数据包含无法解析的引用:'http://ServerName:98/MyService.svc/mex" 元数据包含无法解析的引用:'http://ServerName:98/MyService.svc/mex"Can';t为托管在IIS中的netTcpBinding的WCF服务添加服务引用,wcf,iis,nettcpbinding,Wcf,Iis,Nettcpbinding,对于已部署到IIS的服务,我有以下配置。我可以使用URL将该服务的服务引用添加到wsHttpBinding端点,但无法使用URL将其添加到mexHttpBinding端点(我希望将客户端切换为使用netTcpBinding) 我得到的错误是: 下载“”时出错http://ServerName:98/MyService.svc/mex" 请求失败,HTTP状态为400:请求错误 元数据包含无法解析的引用:'http://ServerName:98/MyService.svc/mex" 元数据包含无
最奇怪的是,这个配置几乎是从我配置和部署的另一个服务一字不差地复制过来的,我能够使用mexHttpBinding端点成功地向客户机添加服务引用。原始服务的配置如下所示:
<system.web>
<compilation debug="true"
targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding_MyOtherService" />
</netTcpBinding>
<wsHttpBinding>
<binding name="wsHttpBinding_MyOtherService"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" />
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehaviour"
name="MyOtherService.MyOtherService">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="wsHttpBinding_MyOtherService"
name="MyOtherServiceEndpoint"
contract="MyOtherService.IMyOtherService" />
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="netTcpBinding_MyOtherService"
name="MyOtherServiceNetTcpEndpoint"
contract="MyOtherService.IMyOtherService" />
<endpoint address="mex"
binding="mexHttpBinding"
bindingConfiguration=""
name="MyOtherServiceMexHttpBindingEndpoint"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://ServerName:97/" />
<add baseAddress="net.tcp://ServerName:970/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"
policyVersion="Policy15" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<windowsAuthentication includeWindowsGroups="true"
allowAnonymousLogons="false" />
</serviceCredentials>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
正如您所注意到的,配置中唯一相关的差异是netTcpBinding端点和mexHttpBinding端点的地址。最初,我开始时两个地址都是空的,但由于我一直在努力让它工作,我在其中添加了显式地址
此外,两个服务在IIS中的配置相同,即在相关端口上启用和配置net.tcp绑定。它们还分别在同一台服务器上运行单独的站点和单独的应用程序池(并且两个应用程序池都以相同的身份运行)
非常感谢您的帮助。在IIS中使用服务时,您不能在端点配置中设置绝对URL。根URL由IIS控制,它遵循Web站点(指定端口)/Web应用程序/虚拟目录/SVC文件的公共结构。只能指定在.svc文件之后指定的地址的相对部分 设置完全绝对地址和基址仅适用于自托管方案
即使您使用wsHttpBinding端点添加服务引用,您仍然应该能够将其切换到netTcpBinding端点,因为该端点应该在WSDL中描述(如果您删除这些绝对地址)。应在客户端的配置文件中配置这两个端点。然后您只需要将端点配置的名称传递给服务存根(WCF代理)的构造函数。解决了它。对于我们部署到的每个环境,我们都有一个Web.{Environment}.config,由于Web.config上的文件锁(可能没有签出TFS),因此在构建时没有通过Web.config复制正确的配置
其中一件事我真的应该先检查一下,但当它以前一直工作,然后突然在没有任何警告的情况下坏掉时,我从来没有想过检查。正如我所说,我最初没有NetCpBinding的地址,只有“mex”作为mexHttpBinding的地址,这不起作用。这是我在另一个服务中使用的配置,它在那里工作。
<system.web>
<compilation debug="true"
targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding_MyOtherService" />
</netTcpBinding>
<wsHttpBinding>
<binding name="wsHttpBinding_MyOtherService"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" />
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehaviour"
name="MyOtherService.MyOtherService">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="wsHttpBinding_MyOtherService"
name="MyOtherServiceEndpoint"
contract="MyOtherService.IMyOtherService" />
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="netTcpBinding_MyOtherService"
name="MyOtherServiceNetTcpEndpoint"
contract="MyOtherService.IMyOtherService" />
<endpoint address="mex"
binding="mexHttpBinding"
bindingConfiguration=""
name="MyOtherServiceMexHttpBindingEndpoint"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://ServerName:97/" />
<add baseAddress="net.tcp://ServerName:970/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"
policyVersion="Policy15" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<windowsAuthentication includeWindowsGroups="true"
allowAnonymousLogons="false" />
</serviceCredentials>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>