WCF Port Configuration Error

I have two services configured through a configuration file. Each of them listens for one http and one https address. The problem is how to configure the ports. If I configure HTTP ports to the same value and https ports to a different value, when debugging the entire project, I get the following error message in the WCF Service Host:

Status: Error System.ServiceModel.AddressAlreadyInUseException: HTTP could not register the URL https: // +: 8002 / Services / xxxService / because another application is using TCP port 8002. ---> System.Net.HttpListenerException: the process cannot access the file because it is being used by another process

If I configure the four ports (http and https) to different values, and none of the https values ​​is the value of the ssl port configured and certified in IIS, I get the following exception when calling the service (but both services are running on the WCF service host):

An error occurred while creating the HTTP request https: // localhost: 8000 / Services / yyyService / . This may be due to the fact that the server certificate is not configured correctly with HTTP.SYS in HTTPS case. It can also be caused by a security binding mismatch between the client and server.

If I configure the first service to use the SSL port (443), then only the second service starts (the one with the β€œwrong” https port). Error message for the first service again:

System.ServiceModel.AddressAlreadyInUseException: HTTP could not register the URL https: // +: 443 / Services / xxxService / because another application is using TCP port 443. ---> System.Net.HttpListenerException: the process cannot access the file because it is being used by another process

In addition, I get an exception when calling the second service:

An error occurred while creating the HTTP request https: // localhost / Services / yyyService / . This may be due to the fact that the server certificate is not configured correctly with HTTP.SYS in HTTPS case. It can also be caused by a security binding mismatch between the client and server.

When I configure both services to use 443 for https, well ... then nothing starts. And I get all sorts of strange exceptions - the clientcredentials are read-only, the handshake meets an unexpected packet format, something about the remote address, etc.

I configured both addresses in the web.config file as follows:

<baseAddresses> <add baseAddress="http://localhost:port1/Services/xxxService/" /> <add baseAddress="https://localhost:port2/Services/xxxService/" /> </baseAddresses> [...] <baseAddresses> <add baseAddress="http://localhost:port3/Services/yyyService/" /> <add baseAddress="https://localhost:port4/Services/yyyService/" /> </baseAddresses> 

I’ve been trying to run this thing for two days now, so any help will be appreciated.

PS. In Visual Studio, I configured IIS as a development server, not a Visual Studio web development server.

EDIT:

  <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> <services> <service name="namespace.xxxService" behaviorConfiguration="default"> <host> <baseAddresses> <add baseAddress="http://localhost:8000/Services/xxxService/" /> <add baseAddress="https://localhost:8001/Services/xxxService/" /> </baseAddresses> </host> <endpoint address="" binding="wsHttpBinding" bindingConfiguration="defaultWsHttpBinding" contract="namespace.IxxxService" /> <endpoint address="mex/" binding="mexHttpBinding" contract="IMetadataExchange" bindingConfiguration="" /> </service> <service name="namespace.yyyService" behaviorConfiguration="default"> <host> <baseAddresses> <add baseAddress="http://localhost:8003/Services/yyyService/" /> <add baseAddress="https://localhost:8004/Services/yyyService/" /> </baseAddresses> </host> <endpoint address="" binding="wsHttpBinding" bindingConfiguration="defaultWsHttpBinding" contract="namespace.IyyyService" /> <endpoint address="mex/" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <client> <endpoint address="https://localhost:8001/Services/xxxService/" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IxxxService" contract="namespace.IxxxService" name="WSHttpBinding_IxxxService" /> <endpoint address="https://localhost:8001/Services/yyyService/" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IyyyService" contract="namespace.IyyyService" name="WSHttpBinding_IyyyService" /> </client> <behaviors> <serviceBehaviors> <behavior name="default"> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> <serviceCredentials> <userNameAuthentication userNamePasswordValidationMode="MembershipProvider" membershipProviderName="SqlMembershipProvider" /> </serviceCredentials> <serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="SqlRoleProvider" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <wsHttpBinding> <binding name="defaultWsHttpBinding"> <security mode="TransportWithMessageCredential"> <message clientCredentialType="UserName" /> <transport clientCredentialType="None" /> </security> </binding> <binding name="WSHttpBinding_IyyyService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false" > <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="TransportWithMessageCredential"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" /> </security> </binding> <binding name="WSHttpBinding_IxxxService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="TransportWithMessageCredential"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" /> </security> </binding> </wsHttpBinding> </bindings> </system.serviceModel> 
+4
source share
2 answers

Your "server certificate is not configured properly" error may be associated with you using "localhost" to access the service. Perhaps your certificate uses something else, such as a machine name.

Try changing the address to the name of the machine.

You also need to specify in the settings that you use for transport security for the https endpoint.

+1
source

Have you configured an SSL certificate on the port? (if the port is available for your service) Have you tried to host your service in IIS?

http://msdn.microsoft.com/en-us/library/ms733791.aspx

0
source

All Articles