簡體   English   中英

一個服務,多個端點,WCF上的多個綁定。 為什么我無法達到我的終點?

[英]One service, multiple endpoints, multiple bindings on WCF. Why can't I reach my endpoints?

我有一個由IIS運行的WCF服務。 我想創建兩個使用相同服務的不同客戶端(WPF和WP7)。 WPF客戶端已使用wsHttpBindinghttps與端點一起工作。 可悲的是WP7沒有做wsHttpBinding ,只有BasicHttpBinding 所以我想我會為這兩個端口暴露不同的端點,所以他們可以訪問相同的服務,但是使用不同的綁定,什么不是......

這是我在IIS上的Web.config:

<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="TransportSecurity">
        <reliableSession enabled="true" />
          <security mode="TransportWithMessageCredential" >
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </wsHttpBinding>
      <basicHttpBinding>
        <binding name="BasicTransportSecurity">
           <security mode="Transport">
              <transport clientCredentialType="None"/>
           </security>
         </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SmartCook2.Server.ISmartCookServiceBehavior">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service behaviorConfiguration="SmartCook2.Server.ISmartCookServiceBehavior"
        name="SmartCook2.Server.SmartCookService">
        <endpoint address="WS" binding="wsHttpBinding" bindingConfiguration="TransportSecurity"
          name="WS" contract="SmartCook2.Server.ISmartCookService" />
        <endpoint address="Basic" binding="basicHttpBinding" bindingConfiguration="BasicTransportSecurity"
          name="Basic" contract="SmartCook2.Server.ISmartCookService" />
        <endpoint address="mex" binding="mexHttpsBinding" name="mex"
          contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
<connectionStrings>
    <add name="SmartCookDBEntities" connectionString="metadata=res://*/SmartCookContext.csdl|res://*/SmartCookContext.ssdl|res://*/SmartCookContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=RENDERBETYAR;initial catalog=SmartCookDB;integrated security=True;pooling=False;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

</configuration>

現在,如果我做對了,應該可以在以下地址訪問端點:

https://localhost/IISHostedSmartCook/SmartCookService.svc/Basic
https://localhost/IISHostedSmartCook/SmartCookService.svc/WS
https://localhost/IISHostedSmartCook/SmartCookService.svc/mex

如果我在瀏覽器中查看它們,我什么也得不到。 沒有例外,但也沒有任何內容。 使用基地址(直到.svc部分)我得到默認服務頁面,我可以訪問wsdl,它是有效的。 據我所知,它有正確的端點,我的服務方法等。

如果我嘗試將ServiceReference添加到我的WP7項目是Visual Studio,我只能在基地址下看到我的服務(特定的端點地址不返回任何內容)。 如果我添加它,類就會生成正確的,只有我不能調用我的任何服務的方法,並且我收到錯誤消息“沒有端點在此地址偵聽”。 (如果我使用服務客戶端的構造函數需要端點名稱,也會發生這種情況。)

我究竟做錯了什么?

點擊此處查看詳細說明。

您需要指定的是endpoints的地址:

  <service behaviorConfiguration="SmartCook2.Server.ISmartCookServiceBehavior"
    name="SmartCook2.Server.SmartCookService">
    <endpoint address="http://localhost/Service.svc/WS" binding="wsHttpBinding" bindingConfiguration="TransportSecurity"
      name="WS" contract="SmartCook2.Server.ISmartCookService" />
    <endpoint address="http://localhost/Service.svc/Basic" binding="basicHttpBinding" bindingConfiguration="BasicTransportSecurity"
      name="Basic" contract="SmartCook2.Server.ISmartCookService" />
    <endpoint address="" binding="mexHttpsBinding" name="mex"
      contract="IMetadataExchange" />
  </service>
<services>
...
      <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
         <host>
            <baseAddresses>
               <add baseAddress="https://localhost/IISHostedSmartCook/SmartCookService.svc"/>
            </baseAddresses>
        </host>
   </service>
</services>
...

您的所有配置都是正確的,如果您檢查wsdl,SOAP:address屬性將具有您指定的位置,即:

https://localhost/IISHostedSmartCook/SmartCookService.svc/Basic
https://localhost/IISHostedSmartCook/SmartCookService.svc/WS
https://localhost/IISHostedSmartCook/SmartCookService.svc/mex

在項目中添加引用時,只需要使用所需的相應端點,即如果要使用basicHttpBinding,則使用其地址為

https://localhost/IISHostedSmartCook/SmartCookService.svc/Basic

當您在IE中瀏覽這些地址時,您將看不到任何絕對正確的地址。 為了使其更加敏感,請將localhost替換為您所在網絡上應該可見的計算機名稱,以便可以通過網絡訪問這些服務。

還嘗試構建一個.NET客戶端來調用服務並確保您的服務正常運行。

這里回答: WCF:單個服務的多個綁定配置

基本上你不能在這里提到的相同的URI上有不同的綁定

但是,您可以在同一個綁定中使用不同的綁定配置。

我相信您可能需要將終點地址更改為相對位置:

<endpoint address="/WS" 

<endpoint address="/Basic"

mex地址是一種特殊情況,因此不需要更改。

有關更多詳細信息,請參閱MSDN文檔指定端點地址

暫無
暫無

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

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