2017-01-23 62 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" />