12

私がやろうとしているのは、単一の WCF サービスを HTTP スキームである開発環境で動作させることと、HTTPS スキームである本番環境で同じサービスを動作させることです。2 つの Https エンドポイント (接尾辞が「Https」のエンドポイント) を削除すると、開発環境で機能します。同様に、2 つの Http エンドポイントのみを削除すると、運用環境で機能します。可能であれば、web.config に 4 つのエンドポイントすべてを含めたいと考えています。

私のエンドポイントは以下に定義されています:

<endpoint address="/Web" 
        behaviorConfiguration="AjaxBehavior"
        binding="wsHttpBinding" 
        bindingConfiguration="web" 
        name="Web"
        contract="Service" />
<endpoint address="/Custom"
        binding="customBinding" 
        bindingConfiguration="custom" 
        name="Custom"   
        contract="Service" />
<endpoint 
        address="/WebHttps" 
        behaviorConfiguration="AjaxBehavior"
        binding="wsHttpBinding" 
        bindingConfiguration="webHttps" 
        name="WebHttps"
        contract="Service" />
<endpoint address="/CustomHttps"
        binding="customBinding" 
        bindingConfiguration="customHttps" 
        name="CustomHttps" 
        contract="Service" />

編集済み:質問を編集して、取得しているエラーとバインディング セクション (以下) を追加しています。質問の新しい長さで申し訳ありません。

エラーは次のとおりです。

さらに、本番サイトは「SSLが必要」に設定されています。それは変えられません。

バインディング構成は次のとおりです。

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"  />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="AjaxBehavior">
      <enableWebScript/>
    </behavior>
  </endpointBehaviors>
</behaviors>

<bindings>
  <customBinding>
    <binding name="custom">
      <textMessageEncoding>
        <readerQuotas maxDepth="7000000" maxStringContentLength="7000000"
            maxArrayLength="7000000" maxBytesPerRead="7000000"
            maxNameTableCharCount="7000000" />
      </textMessageEncoding>

      <httpTransport maxBufferPoolSize="7000000" maxReceivedMessageSize="7000000"
          maxBufferSize="7000000" />
    </binding>
    <binding name="customHttps">
      <textMessageEncoding>
        <readerQuotas maxDepth="7000000" maxStringContentLength="7000000"
            maxArrayLength="7000000" maxBytesPerRead="7000000"
                  maxNameTableCharCount="7000000" />
      </textMessageEncoding>

      <httpsTransport maxBufferPoolSize="7000000" maxReceivedMessageSize="7000000"
          maxBufferSize="7000000" />

    </binding>
  </customBinding>

  <webHttpBinding>
    <binding name="web"  maxBufferPoolSize="70000000"
        maxReceivedMessageSize="70000000">
      <readerQuotas maxDepth="70000000" maxStringContentLength="70000000"
          maxArrayLength="70000000" maxBytesPerRead="70000000"
          maxNameTableCharCount="70000000" />
      <security mode="None" />
    </binding>

    <binding name="webHttps" maxBufferPoolSize="70000000"
        maxReceivedMessageSize="70000000">

      <readerQuotas maxDepth="70000000" maxStringContentLength="70000000"
                maxArrayLength="70000000" maxBytesPerRead="70000000"
                maxNameTableCharCount="70000000" />

      <security mode="Transport" />
    </binding>
  </webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

何か案は?

4

5 に答える 5

27

次の手順を実行します-

1) サービスの 2 つのエンドポイントを記述します。1 つは http 用で、もう 1 つは https 用です。

<services>
    <service behaviorConfiguration="MyServiceBehavior" name="JK.MyService">

      <endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="JK.IMyService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>

      <endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="webBindingHTTPS" contract="JK.IMyService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>     

    </service>
  </services>

2) serviceBehaviors で httpGetEnabled="True" httpsGetEnabled="true" の両方を有効にします。

<behaviors>

<serviceBehaviors>      
  <behavior name="MyServiceBehavior">
    <serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="true" />
  </behavior>      
</serviceBehaviors>

<endpointBehaviors>
  <behavior name="WebBehavior">
    <webHttp/>
  </behavior>
</endpointBehaviors>

</behaviors>

3) http と https の 2 つのバインディング構成を記述します。http の場合は security mode="None" を指定し、https の場合は mode="Transport" を指定します。

<bindings>
    <webHttpBinding>

      <binding name="webBinding">
        <security mode="None">
          <transport clientCredentialType="None" />
        </security>
      </binding>

      <binding name="webBindingHTTPS">
        <security mode="Transport">
          <transport clientCredentialType="None" />
        </security>
      </binding>

    </webHttpBinding>
  </bindings>

このリンクを確認してください

于 2010-09-29T18:15:36.213 に答える
4

Visual Studio 2010 と Web アプリケーション プロジェクトの配置を使用している場合は、Web.config 変換構文を使用して、サービス エンドポイントの bindingConfiguration を https 対応のバインド構成にポイントできます。

私にとっては、Web.config ファイル内の 2 つの要素を置き換えるだけでよいことがわかりました。エンドポイントの bindingConfiguration 属性と serviceMetadata の httpsGetEnabled を true に設定する必要があります。

デフォルト (デバッグ) 構成の Web.config を次に示します。

<service name="Service"
            behaviorConfiguration="DefaultBehavior">
    <endpoint name="ServiceEndpoint"
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding"
                contract="IService" />
    </service>
    ...
    <behaviors>
    <serviceBehaviors>
        <behavior name="DefaultBehavior">
            <serviceMetadata httpGetEnabled="True" />
            <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
    </serviceBehaviors>
</behaviors>

Web.Release.config 変換ファイルは次のとおりです。

<behaviors>
    <serviceBehaviors>
        <behavior>
            <serviceMetadata httpsGetEnabled="True" xdt:Transform="Replace" />
            <serviceDebug includeExceptionDetailInFaults="False" xdt:Transform="SetAttributes(includeExceptionDetailInFaults)"/>
        </behavior>
    </serviceBehaviors>
</behaviors>
<services>
    <service>
        <endpoint bindingConfiguration="SecureTransportBinding"
                    xdt:Transform="SetAttributes(bindingConfiguration)"/>
    </service>
</services>

これが私のバインディングの外観ですが、かなり標準的です。上記で使用されている名前に注意してください。

<basicHttpBinding>
    <binding name="SecureTransportBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647">
        <security mode="Transport"/>
        <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"/>
    </binding>
    <binding name="BasicHttpBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647">
        <security mode="None"/>
        <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"/>
    </binding>
</basicHttpBinding>

Web.config 変換の詳細へのリンクは次のとおりです。

http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx

于 2010-10-13T02:22:39.960 に答える
1

エラーが発生する理由はたくさんあります。

    Could not find a base address that matches scheme http for the endpoint
    with   binding WebHttpBinding. Registered base address schemes are [https].

ほとんどの理由は Web.config 設定によるものですが、IIS による可能性もあります。私は同じ問題を抱えていました。http と https の両方のバインドでエンドポイントを防御した場合、IIS->Site->Bindings で作成した Web サイトの http と https のバインドを作成する必要があります。そうしないと、このエラーが発生します。

于 2015-08-26T05:25:26.117 に答える
0

これが、構成からバインドをセットアップできる理由の 1 つです。異なる環境で異なる設定を使用できるようにするためです。

最も簡単な解決策は、makecertを使用して開発環境用のテスト証明書を作成し、開発マシンと運用マシンの両方で HTTPS を使用することです。

もう 1 つの解決策は、インストール パッケージ (msi) を作成し、管理者がインストール中に enpoint 設定を変更できるようにすることです。

編集:

両方のマシンに 4 つのエンドポイントをすべて持つという要件は達成可能ですが、その場合、サービスは実稼働環境で HTTP でも公開され、サービスの WSDL を持つすべての人がそれを知ることになります。

于 2010-09-29T18:15:01.443 に答える
0

既定の受信タイムアウトは 10 分であるため、アイドル時間がその制限を超えると、WCF クライアントは切断されます。接続を維持する必要がある場合はどうすればよいですか?

解決策 1:

サーバーは、クライアントがアイドル状態にならないように定期的に呼び出すためのダミー操作を提供します。

解決策 2:

クライアントとサーバーの両方で、reliableSession を有効にし、receiveTimeout と inactivityTimeout を「無限」に設定します。構成スニペットは次のようになります。

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="WSHttpBinding" receiveTimeout="infinite">
        <reliableSession inactivityTimeout="infinite" enabled="true" />
      </binding>
    </wsHttpBinding>
  </bindings>
  <services>
  ...
  </services>
  ...
</system.serviceModel>
于 2010-12-01T11:30:37.267 に答える