Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
429 views
in Technique[技术] by (71.8m points)

c# - Windows Service hosted WCF over HTTPS

I've created and configured an SSL certificate as per these instructions from MSDN. I'm getting the error message that this question lists, but am not sure how to map the accepted answer in that question to my App.config file. The content of the config file, and the service itself worked correctly over http, it's just over https that the problem is occuring.

My App.config file is currently:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="TransportSecurity">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="LookupServiceHost" behaviorConfiguration="serviceBehaviour">
        <host>
          <baseAddresses>
            <add baseAddress="https://localhost:54321/MyService"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="wsHttpBinding" contract="ILookupService" bindingConfiguration="TransportSecurity" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehaviour">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

The ErrorException returned in the Windows Event Log:

Service cannot be started. System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL https://+:54321/MyService/. Another application has already registered this URL with HTTP.SYS. ---> System.Net.HttpListenerException: Failed to listen on prefix 'https://+:54321/MyService/' because it conflicts with an existing registration on the machine.

Could someone give me a pointer as to how to enable this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you are connecting two different settings. Netsh can be used to add certificate for SSL but also to allow application listening on given port without running under admin account. The exception targets second setting. I haven't seen it before but I assume that you have already registered this port for HTTP so lets try to use (and register) HTTPS on another port or replace previous registration.

Edit:

Open command prompt with elevated privileges (As Admin). First check if SSL cert is assigned to correct port:

netsh http show sslcert

Than check if HTTP listening is registered on that port by calling:

netsh http show urlacl 

If so use following command to remove that registration:

netsh http delete urlacl url=http://+:54321/MyService

Add registration again to support listening on HTTPS:

netsh http add urlacl url=https://+:54321/MyService user=domainuserName

Where user is account used to run your Windows service. If it ia a local account use only userName.

Note: Under https, it appears the wildcard must be used in the urlacl. We cannot write https://localhost:8733/... to match Visual Studios default urlacl for http. This probably makes sense since the requested hostname isn't available until after decryption.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...