2011-06-22 26 views
3

HTTP(基本的なhttpバインディング)バインディングとHTTPS(基本的なhttpバインディング)バインディングの両方を持つWCFサービスプロジェクトを作成できますか?例えば、私が持っているでしょう:HTTPとHTTP WCFサービス

https://localhost:44303/ServiceA.svc ます。http:// localhostを:(私たちはアプリを展開するときに、別のサイト)12345/ServiceB.svc

は、別のサービス・プロジェクトにそれらを置くことにどんな利点があるでしょうが?

答えて

2

すでにHTTPバインディングがある場合、HTTPSバインディングを追加するコードを変更する必要はありません。これはWCFの大きな利点です。別のサイトを追加する代わりに、新しいエンドポイントを構成ファイルに追加するだけです。

次に、HTTPとHTTPSの両方の設定例を示します。
HTTPとHTTPSに対応するnotSecureBindingとsecureBindingの2つの名前付きバインディングがあることがわかります。

<bindings> 
    <basicHttpBinding> 
     <binding name="notSecureBinding" 
       maxBufferSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 
     <security mode="None"/> 
     </binding> 
     <binding name="secureBinding" 
       maxBufferSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 
     <security mode="Transport"> 
      <transport clientCredentialType="None"/> 
     </security> 
     </binding> 
    </basicHttpBinding> 
    </bindings> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name="StandardServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceAuthorization principalPermissionMode="None"/> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <services> 
    <service behaviorConfiguration="StandardServiceBehavior" 
      name="ServiceName"> 
     <endpoint address="" 
       binding="basicHttpBinding" 
       bindingConfiguration="notSecureBinding" 
       contract="Namespace.IService"/> 
     <endpoint address="" 
       binding="basicHttpBinding" 
       bindingConfiguration="secureBinding" 
       contract="Namespace.IService"/> 
     <endpoint address="mex" 
       binding="mexHttpBinding" 
       contract="IMetadataExchange"/> 
    </service> 
    </services> 
+0

@ user472292 - IISでホストしていますか? SSL証明書を作成しましたか?証明書をポートにバインドしましたか? –

+0

httpsエンドポイント経由でメタデータを取得できるようにする必要がある場合は、 'serviceMetadata'要素に' httpsGetEnabled = "true" 'を追加する必要があります。また、もう1つのmexエンドポイントを追加する必要があります。 –

+0

@ user472292 - 私が見せている設定は私のプロダクションプロジェクトのもので、動作しています。 –

0

私はこれを試みたと私は私のセキュアなサービスを消費しようとすると、私は次のエラーを取得する:私は私の安全でないサービスを消費しようとすると

The HTML document does not contain Web service discovery information. Metadata contains a reference that cannot be resolved: 'https://localhost:44304/ExternalOrderProcessing.svc'. There was no endpoint listening at https://localhost:44304/ExternalOrderProcessing.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The remote server returned an error: (404) Not Found.If the service is defined in the current solution, try building the solution and adding the service reference again. 

は、私は次のエラーを取得する:

The HTML document does not contain Web service discovery information. Metadata contains a reference that cannot be resolved: 'http://localhost:5000/LegacyOrderProcessing.svc'. Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:5000/LegacyOrderProcessing.svc. The client and service bindings may be mismatched. The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.. If the service is defined in the current solution, try building the solution and adding the service reference again. 

私はIIS Expressでこれを実行しています。 SSLを許可するようにプロジェクトをセットアップしました。次のように私の設定です:

<services> 
    <service name="ExternalOrderProcessing" behaviorConfiguration="SecureBehavior"> 
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBindingSecure" contract="IExternalOrderProcessing" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
    <service name="LegacyOrderProcessing" behaviorConfiguration="UnsecureBehavior"> 
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="ILegacyOrderProcessing" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 

<behaviors> 
    <serviceBehaviors> 
    <behavior name="SecureBehavior"> 
     <serviceMetadata httpsGetEnabled="true" httpsGetUrl=""/> 
     <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceCredentials> 
     <serviceCertificate findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" /> 
     <clientCertificate> 
      <authentication certificateValidationMode="None" /> 
     </clientCertificate> 
     </serviceCredentials> 
    </behavior> 
    <behavior name="UnsecureBehavior"> 
     <serviceMetadata httpGetEnabled="true" httpGetUrl=""/> 
     <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<bindings> 

    <basicHttpBinding> 
    <!-- Used by external order processing service --> 
    <binding name="BasicHttpBindingSecure" 
      hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="2147483647" 
      maxReceivedMessageSize="2147483647" 
      receiveTimeout="00:05:00" 
      sendTimeout="00:05:00" 
      openTimeout="00:05:00" 
      closeTimeout="00:05:00"> 
     <readerQuotas maxArrayLength="2147483647"/> 
     <security mode="TransportWithMessageCredential"> 
     <transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" /> 
     <message clientCredentialType="Certificate" algorithmSuite="Default" /> 
     </security> 
    </binding> 
    <!-- Used to create binding to internal order processing service --> 
    <binding name="BasicHttpBinding" 
      hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="2147483647" 
      maxReceivedMessageSize="2147483647" 
      receiveTimeout="00:05:00" 
      sendTimeout="00:05:00" 
      openTimeout="00:05:00" 
      closeTimeout="00:05:00"> 
     <readerQuotas maxArrayLength="2147483647"/> 
     <security mode="None" /> 
    </binding> 
    </basicHttpBinding> 

</bindings> 

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

私は2つの別々のプロジェクトにサービスを入れた場合、それが動作します。私がそれをするとき、私は設定のサービスセクションを省略し、name = "BasicHttpBindingSecure"とname = "SecureBehavior"を削除します。

+0

これについて何か考えていますか? – user472292

関連する問題