4

我一直在尝试在 IIS 下托管的服务中添加一个新端点,但在过去一天左右一直无法弄清楚。

这是我的理解:

  • 只要它们具有唯一的地址,您就可以在 IIS 下拥有多个端点。
  • 您可以分配一个基地址,但它将被 IIS 中的虚拟目录设置覆盖。

我的虚拟目录是http://localhost/WcfCert/

<services>
  <service name="WcfCertServer.Service1" behaviorConfiguration="WcfCertServer.Service1Behavior">
    <endpoint address="" binding="wsHttpBinding" contract="WcfCertServer.IService1"/>
    <endpoint address="test" binding="wsHttpBinding" contract="WcfCertServer.IService1"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>

我可以使用http://localhost/wcfcert/service1.svc启动服务

http://localhost/wcfcert/test/service1.svc/test在 IE 或客户端应用程序中没有返回任何内容

我在这里想念什么?

编辑:

所以我做了进一步的测试,这就是我发现的。

如果我启动 WcfTestClient.exe 并添加http://localhost:1523/Service1.svchttp://localhost:1523/Service1.svc/mex它将在该地址下添加两个端点。所以这是我的问题不应该http://localhost:1523/Service1.svc只代表第一个端点吗?为什么添加该地址会同时显示两个端点?

但如果我尝试添加http://localhost:1523/Service1.svc/test我得到

错误:无法从http://localhost:1523/Service1.svc/test获取元数据如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅位于http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:1523/Service1.svc/test的 MSDN 文档的 MSDN 文档 元数据包含无法解析的引用:“ http://localhost:1523/Service1.svc/test ”。 Sendera:BadContextToken无法处理该消息。这很可能是因为操作' http://schemas.xmlsoap.org/ws/2004/09/transfer/Get' 不正确,或者因为消息包含无效或过期的安全上下文令牌,或者因为绑定之间不匹配。如果服务由于不活动而中止通道,则安全上下文令牌将无效。为防止服务过早中止空闲会话,请增加服务端点绑定的接收超时。HTTP GET 错误 URI:http://localhost:1523/Service1.svc/test 下载时出错“ http://localhost:1523 ” /Service1.svc/test '。请求失败,HTTP 状态为 400:错误请求。

4

2 回答 2

2

它实际上是:

http://localhost/wcfcert/service1.svc/test

如果您希望 URL 为“ http://localhost/wcfcert/test/service1.svc ”,则需要在地址属性中指定完整的 URL。

于 2009-07-25T18:44:53.513 回答
0

我最近遇到了类似的问题,我相信原因是因为 WcfTestClient 需要 mex 端点来查询它正在测试的服务的元数据。

当您将服务地址添加"http://localhost:1523/Service1.svc"到 WcfTestClient 时,它实际上会查询端点"http://localhost:1523/Service1.svc/mex"以获取服务描述。

显示错误“无法从中获取元数据,"http://localhost:1523/Service1.svc/test"因为 WcfTestClient 正在寻找“/test/mex”端点以在“/test”处获取服务的元数据。

要解决此问题,您需要添加另一个端点以提供有关托管在地址“/test”的服务的元数据:

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

这是对我有用的解决方案。

于 2013-12-07T00:19:28.497 回答