2015-07-21 26 views
1

我已經看過幾個SO上的帖子,它們展示瞭如何爲同一服務添加多個端點,但其中沒有實際使用HTTPS,這就是爲什麼我要問這個問題題。相同的WCF服務具有不同的EndPoints和不同的綁定對於HTTPS

我有什麼

我有一個Web服務,

https://portal.gov.com/us/216/_vti_bin/external/gov.svc 

我想

我想打電話給使用兩種不同的配置這個Web服務,有什麼和綁定與不同的終端,但相同的網址? (對不起,也許我很困惑與端點的概念)

這裏是我的web.config的樣子,

<?xml version="1.0" encoding="utf-8" standalone="yes" ?> 
<configuration> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="Gov_ServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
     </behavior> 
     </serviceBehaviors> 

     <endpointBehaviors> 
     <behavior name="restBehavior"> 
      <webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" /> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 

    <bindings> 
     <webHttpBinding> 
     <binding name="Gov_webHttpBinding"> 
      <security mode="Transport"> 
      <transport clientCredentialType="InheritedFromHost" /> 
      </security> 
     </binding> 
     </webHttpBinding> 
     <!--<basicHttpBinding> 
     <binding name="Gov_BasicHttpBinding"> 
      <security mode="Transport"> 
      <transport clientCredentialType="InheritedFromHost" /> 
      </security> 
     </binding> 
     </basicHttpBinding>--> 
    </bindings> 

    <services> 
     <service name="Portal.WebServices.External.Gov" behaviorConfiguration="Gov_ServiceBehavior"> 
     <endpoint address="" binding="webHttpBinding" behaviorConfiguration="restBehavior" contract="Portal.WebServices.External.IGov" bindingConfiguration="Gov_webHttpBinding"/> 
     <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/> 
     <!--<endpoint address="basic" binding="basicHttpBinding" contract="Portal.WebServices.External.IGov" bindingConfiguration="Gov_BasicHttpBinding"/>--> 
     </service> 
    </services> 

    </system.serviceModel> 

</configuration> 

WHERE IS THE PAIN

它僅適用,直到我把basicHttpBinding的評論並且它是端點,只要我包含它,我就會收到沉默錯誤。

根據這一點 - https://msdn.microsoft.com/en-us/library/ms751515(v=vs.110).aspx

它應該工作,但因爲我使用HTTPS和增加綁定標籤我的web.config

+0

我不認爲'WebHttpBinding'被認爲與'BasicHttpBinding'類似。當一個構建一個restful的wcf服務時,需要使用'WebHttpBinding'.And沒有'MetaData'暴露的消費。 –

+0

'HTTPS'絕對不是這種情況,但是你公開你的服務的方式,也就是你選擇的綁定組合可能並不是同時工作。你可以嘗試刪除WebHttpBinding並添加另一個WsHttpBinding來代替走着瞧吧。 –

+0

如果使用WebHttpBinding,則不會公開MetaData數據。 –

回答

0

什麼你正在努力實現是不可能沒有可能。您不能使用完全相同的端點應用兩個不同的綁定。如果試圖再次讀取您的參考here很顯然,樣本有兩個不同的端點:

首先地址是http://localhost/servicemodelsamples/service.svc和第二 是http://localhost/servicemodelsamples/service.svc/secure。這兩個端點彼此不同,但共享相同的合同。

第二個端點只是相對於基地址http://localhost/servicemodelsamples/service.svc

我希望這可以讓您明確約束力和終點。

相關問題