c# - IIS 下的多个端点

标签 c# .net wcf iis endpoints

我一直在尝试在 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我明白了

Error: Cannot obtain Metadata from http://localhost:1523/Service1.svc/test If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:1523/Service1.svc/test Metadata contains a reference that cannot be resolved: 'http://localhost:1523/Service1.svc/test'. Sendera:BadContextTokenThe message could not be processed. This is most likely because the action 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.HTTP GET Error URI: http://localhost:1523/Service1.svc/test There was an error downloading 'http://localhost:1523/Service1.svc/test'. The request failed with HTTP status 400: Bad Request.

最佳答案

实际上是:

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

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

关于c# - IIS 下的多个端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1182725/

相关文章:

c# - 如果 API 已经是多线程的,您是否需要对调用者进行多线程处理? ASP.Net MVC

c# - 存储库模式 - 全局存储库是个好主意吗?

c# - 禁用按钮时的奇怪问题

c# - WCF 从引用程序集返回某种类型的对象

rest - 使用 REST 创建作业并在 jenkins 中执行它们

c# - 将 Json 代码转换为 C#(数字作为键)

c# - "Non-nullable event must contain a non-null value when exiting constructor"

c# - 如何捕获自定义文件夹上的 Outlook 约会删除事件?

c# - 在网络浏览器上捕获 DragEnter 和 Drag Drop 事件

.net - WCF 与方法 IDispatchMessageInspector.AfterReceiveRequest 的返回有什么关系?