2017-01-23 60 views
0

我正在實現需要使用Json對象的WCF服務。這工作到目前爲止。現在,我希望服務只接受https,所以沒有http。執行Json和https的Wcf服務

對於這兩個要求,我發現了幾個樣本,我已經測試,似乎工作。但是我無法將兩個要求都集成到一個配置文件中。

這是我的服務配置:

<?xml version="1.0"?> 
<configuration> 

    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    </appSettings> 

    <system.web> 
    <compilation debug="true" targetFramework="4.5.2" /> 
    <httpRuntime targetFramework="4.5.2"/> 
    </system.web> 

    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="serviceBehavior" name="SMApi.SApi"> 
     <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" 
      bindingConfiguration="" contract="SMApi.ISApi" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <!--/--> 
     <behavior name="serviceBehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     <!--/--> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
     </behavior> 
     </serviceBehaviors> 
     <!--/--> 
     <endpointBehaviors> 
     <behavior name="web"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
     <!--/--> 
    </behaviors> 
    <protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https"/> 
    </protocolMapping> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <directoryBrowse enabled="false"/> 
    </system.webServer> 

</configuration> 
+0

嘗試設置安全模式對'webHttpBinding'運輸。你需要爲你的配置添加一個綁定配置部分。 – Tim

回答

0

嘗試添加綁定配置爲<webHttpBinding>和設置安全模式運輸。您需要明確地將綁定配置設置爲您的端點。

<bindings> 
    <webHttpBinding name="SMApiWebhttpBinding"> 
    <security mode="Transport" /> 
    </webHttpBinding> 
</bindings> 

然後在你的端點通過binding Configuration屬性參考上面的綁定配置:

<service behaviorConfiguration="serviceBehavior" 
     name="SMApi.SApi"> 
    <endpoint address="" behaviorConfiguration="web" 
      binding="webHttpBinding" 
      bindingConfiguration="SMApiWebHttpBinding" 
      contract="SMApi.ISApi" />