我可以有一个同时具有HTTP(基本http绑定)和HTTPS(基本http绑定)绑定的WCF服务项目吗?例如,我会:HTTP和HTTP WCF服务
https://localhost:44303/ServiceA.svc 的http://本地主机:12345/ServiceB.svc
会不会有任何好处,以将它们放入单独的服务项目(和单独的网站,当我们部署应用程序) ?
我可以有一个同时具有HTTP(基本http绑定)和HTTPS(基本http绑定)绑定的WCF服务项目吗?例如,我会:HTTP和HTTP WCF服务
https://localhost:44303/ServiceA.svc 的http://本地主机:12345/ServiceB.svc
会不会有任何好处,以将它们放入单独的服务项目(和单独的网站,当我们部署应用程序) ?
如果您已经有HTTP绑定,则不需要更改代码以添加HTTPS绑定。这是WCF的一大优势。除了添加单独的站点之外,您只需将新的端点添加到配置文件。
下面是使用HTTP和HTTPS进行配置的示例。
您可以看到有两个命名的绑定:notSecureBinding和secureBinding,它们分别对应于HTTP和HTTPS。
<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>
我尝试这一点,当我尝试使用我的安全服务,我得到以下错误:
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" />
如果我把业务分为两个独立的项目,它的工作原理。当我这样做时,我省略了配置中的服务部分,并删除名称=“BasicHttpBindingSecure”和名称=“SecureBehavior”。
对此有任何想法? – user472292
@ user472292 - 你在IIS上托管吗?您是否创建了SSL证书?你是否将证书绑定到端口? –
如果您需要通过https端点检索元数据,则需要将'httpsGetEnabled =“true”'添加到'serviceMetadata'元素。您还需要添加一个mex端点。 –
@ user472292 - 我显示的配置来自我的生产项目并且正在运行。 –