服务端点与主机基地址

服务端点与主机基地址

本文介绍了WCF 服务端点与主机基地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我对服务端点和主机基址的用途有点困惑.在我到目前为止所经历的所有示例中,他们都谈到使用所需的绑定设置端点,您通常可以导航到这些端点

然而,当我使用以下配置来设置和托管我的服务时,它似乎只公开了主机基地址.

 <system.web><编译调试=真"/></system.web><!-- 部署服务库项目时,必须将config文件的内容添加到宿主机的app.config 文件.System.Configuration 不支持库的配置文件.--><system.serviceModel><服务><服务名称="HostService.EvalService"><端点地址="http://localhost:8080/basic"binding="basicHttpBinding" contract="HostService.IEvalService"/><端点地址="http://localhost:8080/ws"binding="wsHttpBinding" contract="HostService.IEvalService"/><端点地址=mex"绑定=mexHttpBinding"name="mex" contract="IMetadataExchange"/><基地址><add baseAddress="http://localhost:8080/EvalsService"/></baseAddresses></host></服务></服务><行为><服务行为><行为名称=""><serviceMetadata httpGetEnabled="true"/><serviceDebug includeExceptionDetailInFaults="false"/></行为></serviceBehaviors></行为></system.serviceModel></配置>

有人可以向我解释一下吗?

解决方案

在 IIS 上承载 WCF 服务时,基地址只能是 .svc 文件的 URL.如果您指定任何其他基地址,它将被忽略.您仍然可以为端点指定相对 URI,例如 address="basic"address = "ws".然后端点上的地址在这种情况下变为 /basic/ws.>

so i'm a litle confused over what the service endpoints and host base address is for. In all the examples i have walked through so far they talk about setting up the endpoints with the required bindings and you can normally navigate to those endpoints

Hoever when i use the following config to set up and host my service it only seems to expose the Hosts base address.

    <configuration>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <!-- When deploying the service library project, the content of the config file must be added to the host's
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <services>
          <service name="HostService.EvalService">
            <endpoint address="http://localhost:8080/basic"
              binding="basicHttpBinding" contract="HostService.IEvalService" />
            <endpoint address="http://localhost:8080/ws"
              binding="wsHttpBinding" contract="HostService.IEvalService" />
            <endpoint address="mex" binding="mexHttpBinding"
              name="mex" contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8080/EvalsService" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>

Can someone explain this to me?

解决方案

When you host the WCF service on IIS, the base address can only be the URL to the .svc file. If you specify any other base address, it's ignored. You can still specify the relative URI for your endpoints, such as address="basic" or address = "ws". Then the address on the endpoint becomes <URL to the .svc file>/basic and <URL to the .svc file>/ws in this case.

这篇关于WCF 服务端点与主机基地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 00:38