使用https进行WCF服务自托管

时间:2013-09-02 19:17:32

标签: wcf ssl windows-services client-certificates wcfserviceclient

Currenlty有一个Wcf服务作为Windows服务托管在我们的一个客户端机器上,实际上目前这是正常的http调用。由于我们需要使用https而不是http,因此我们修改了app.config,但在启动服务后,https网址无法正常工作。然后我们使用netsh http add urlacl url=https://+:18732/Peripheral/ user=Everyone尝试了网址预订。然后我们再次重新启动服务它无法使用访问https网址。

我们在URl浏览器中收到错误•确保启用了TLS和SSL协议。

这与任何证书问题有关吗?如果是这样我们怎么能够解决这个问题?

web.config如下所示: -

<system.serviceModel>
<standardEndpoints />
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  <bindings>
    <basicHttpBinding>
    <binding name ="soapBinding">
    <security mode="Transport">
    <transport clientCredentialType="None"/>
    </security>
    </binding>
    </basicHttpBinding>
    <webHttpBinding>
 <binding name="Bind1" crossDomainScriptAccessEnabled="true">
<security mode="Transport">
 <transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>  
    </bindings>
    <services>
      <service name="Peripheral.Server.Impl.PeripheralServiceImpl" behaviorConfiguration="SvcBhvr">
<host>
<baseAddresses>
  <add baseAddress="https://localhost:18732/Peripheral/" />
  </baseAddresses>
</host>
<endpoint address="https://localhost:18732/Peripheral/" binding="webHttpBinding" behaviorConfiguration="EndPBhvr" bindingConfiguration="Bind1" 
contract="Peripheral.Server.Contract.IPeripheralService">
 <!--<identity>
    <dns value="localhost" />
  </identity>-->
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="EndPBhvr">
<webHttp /> 
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="SvcBhvr">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

任何人都知道如何解决这个问题以及我们需要做什么,以便我们能够从Windows服务中访问URL作为https?

1 个答案:

答案 0 :(得分:4)

您可能还需要使用netsh或HttpConfig工具将ssl证书绑定到特定端口号,具体取决于操作系统版本。详细说明可以在here

找到

在你的情况下,它可能是:

netsh http add sslcert ipport=0.0.0.0:18732 certhash=<certhash> appid={<guid>} clientcertnegotiation=enable

其中

certhash =您的证书Thumbprint(X509Certificate2.Thumbprint)

appid =可能只是Guid.NewId()