2012-08-03 61 views
0

如果你是一個初學者,很難拿起網絡服務,這並不是因爲這個概念很難 - 它不是 - 但是因爲這項技術經歷了很多曲折和搜索,Google尋求幫助沒有幫助,如果你所得到的回報是稍微不同的實現的答案。將「HelloWorld」WCF Web服務轉換爲使用https?

[例如我們的解決方案還從未有過一個.svc文件或.asmx文件,儘管這些答案中經常露面,我們的web.config中沒有任何behaviorbinding元素,正如其他人似乎]

我們已經使用了一個教程來設置我認爲在IIS6上運行的「WCF Web服務」。它工作正常。

但我們想將其轉換爲使用加密/ https。

因此,我們已經檢查了需要在IIS安全通道箱:
enter image description here

不知道還有什麼可以在那裏配置,但是...無論如何,繼續前進。接下來,我會想象我們必須修改我們的web.config文件...但是什麼和如何?以下是我們在我們的web.config system.serviceModel下了:

<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment> 
    <standardEndpoints> 
     <webHttpEndpoint> 
      <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint> 
     </webHttpEndpoint> 
    </standardEndpoints> 
</system.serviceModel> 

那麼,我們下一步需要做什麼?

回答

0

好了,所以很難硬性規定不ALL不幸的代碼,但這裏的概述:

你會希望將這些綁定和行爲加入到web.config中。

我會從basicHttpBinding開始,只是讓它像當前一樣工作,但是這次你會指定你的綁定細節而不是使用默認值。要「關閉」https,請將bindingConfiguration中的安全模式更改爲無。

你有這樣的事情對你的WCF服務,當你完成:

<services> 
    <service behaviorConfiguration="webServiceClientBehavior" name="My.Service.ServiceName"> 
      <endpoint address="http://localhost:5803/LSClient" binding="basicHttpBinding" bindingConfiguration="secureBinding" contract="My.Service.IServiceName"/> 
    </service> 
</services> 

對於bindingConfiguration:

<bindings> 
     <basicHttpBinding> 
     <binding name="secureBinding"> 
      <security mode="Transport" /> 
     </binding> 
     </basicHttpBinding> 
</bindings> 

對於behaviorConfiguration:

<serviceBehaviors> 
     <behavior name="webServiceClientBehavior"> 
      <!--For MetaData--> 
      <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:5802/LSClientMD"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
</serviceBehaviors> 

這些將需要爲您的實施稍作調整,但這是一個基本的概述。