2017年7月8日土曜日

WCFでhttps通信[web.config]

 ■VisualStudio2013だとprotocolMappingが設定されなかったので自分で追加しないといけなかった。
■VisualStudio2017ではprotocolMappingは自動で追加された。

protocolMappingでhttpsがないと、エンドポイントがアクティブ化できないとエラーになる。
このweb.configは適当に変更すること。

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.2" />
    <httpRuntime targetFramework="4.6.2"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfService1.Service1">
        <endpoint address="Service1.svc" binding="basicHttpsBinding" bindingConfiguration="SecureBinding"
          contract="WcfService1.IService1" />
        <host>
          <baseAddresses>
            <add baseAddress="https://[servername]/test" />
          </baseAddresses>

        </host>
      </service>
    </services>
    <bindings>
      <basicHttpsBinding>
        <binding name="SecureBinding" />
      </basicHttpsBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- メタデータ情報の開示を避けるには、展開する前に下の値を false に設定します -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- デバッグ目的で障害発生時の例外の詳細を受け取るには、下の値を true に設定します。例外情報の開示を避けるには、展開する前に false に設定します -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add scheme="https" binding="basicHttpsBinding" bindingConfiguration="SecureBinding" />
    </protocolMapping>   

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        デバッグ中に Web アプリケーションのルートを直接参照するには、下の値を true に設定します。
        Web アプリケーション フォルダーの情報開示を避けるには、展開する前に false に設定します。
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

0 件のコメント:

コメントを投稿