簡體   English   中英

WCF,更改端點的baseAdress

[英]WCF, changing the baseAdress of an endpoint

我有一些關於以下配置文件的問題:

<system.serviceModel>
  <bindings />
  <services>
    <service behaviorConfiguration="WcfReporting.Service1Behavior"
             name="WcfReporting.Service1">
      <endpoint address="" 
                binding="basicHttpBinding" bindingConfiguration=""
                contract="WcfReporting.IService1">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" 
                contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:5050/" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="WcfReporting.Service1Behavior" >
        <!-- To avoid disclosing metadata information, set the value below to false 
             and remove the metadata endpoint above before deployment -->
        <serviceMetadata httpGetEnabled="true"/>
        <!-- To receive exception details in faults for debugging purposes, 
             set the value below to true. Set to false before deployment to 
             avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>
  1. 為什么當我按F5重新啟動服務時,服務以此URL http:// localhost:2752 / ...開始,為什么不是我在baseAddresses中指定的5050。

  2. 如何添加其他端點? 我嘗試使用endpoint address =“/ Address2”binding =“basicHttpBinding”contract =“WcfReporting.IService1”/>

我應該如何能夠訪問該服務,不僅可以使用http:// localhost / VirtualDir / ,還可以使用http:// localhost / VirtualDir / address2或者它是如何工作的?

如果您在Visual Studio 2005或更高版本中托管Cassini,則可以使用Project / Properties / Web / Use Visual Studio Development Server / Specific Port指定端口。

默認情況下,端口將自動分配 - 這對Web服務沒有多大幫助,因為您的客戶可能希望使用固定的URL。

在IIS或Cassini中托管時,無需在配置文件中指定<baseAddresses> - 基本URL由Web服務器提供。 自托管時使用<baseAddresses>元素。

如何添加其他端點? 我嘗試使用endpoint address =“/ Address2”binding =“basicHttpBinding”contract =“WcfReporting.IService1”/>

您在此端點中指定的地址需要是本地和相對的 - 例如,只需指定

<endpoint address="Address2"
          binding="basicHttpBinding"
          contract="WcfReporting.IService1" />

這將在完整的地址創建一個端點

net.tcp://localhost:5050/Address2

但正如Darin已經指出的那樣 - 如果您使用IIS / WAS來托管您的服務,則* .svc文件所在的虛擬目錄將優先,並且將忽略指定的基址。 為了真正使用基地址,您需要在控制台應用程序或Windows服務中自行托管服務。

如果使用Web服務器(如Cassini或IIS)來托管WCF服務,則將從此服務器提供基本地址。 另請注意,您無法通過HTTP使用TCP綁定。 如果您希望能夠設置基地址屬性,則需要自己托管服務(例如,在NT服務,控制台或Windows應用程序中)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM