簡體   English   中英

僅實現Json和https的Wcf服務

[英]Wcf service implementing Json and https only

我正在實現需要與Json對象一起使用的WCF服務。 到目前為止,這是可行的。 現在,我希望該服務僅接受https,因此不接受http。

對於這兩個要求,我都找到了一些經過測試且似乎可以正常工作的示例。 但是我無法將兩個要求都集成到一個配置文件中。

這是我對服務的配置:

<?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>

嘗試為<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" />

暫無
暫無

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

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