Can't access WCF service through https - c#

I setup a WCF application to be hosted by a Windows service. I got this to work correctly and I can navigate to it by going to http://127.0.0.1:1214. Here is the configuration:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="NetworkPrintClient.PrintWebService" behaviorConfiguration="PrintServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://127.0.0.1:1214/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="NetworkPrintClient.IPrintWebService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PrintServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Now I'd like to make this accessible at https://127.0.0.1:1214. After reading several articles about doing this, I end up with the config below. But, I can't browse to the application anymore. I just get a "This site can't be reached" error in Chrome.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="NetworkPrintClient.PrintWebService" behaviorConfiguration="PrintServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="https://127.0.0.1:1214/"/>
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" contract="NetworkPrintClient.IPrintWebService" behaviorConfiguration="HttpBehavior" bindingConfiguration="PrintServiceHttpsBinding"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PrintServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="HttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="PrintServiceHttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add binding="webHttpBinding" scheme="https"/>
</protocolMapping>
</system.serviceModel>
</configuration>
The article I used to get this far is here. I did the part at the bottom about making the certificate and mapping it to my IP and port. I also tried to get this to work with "localhost" and my actual IP address. Can anyone see what I'm doing wrong?

You must to create a certificate selfhosted to localhost, you can use this command line in powersheel
New-SelfSignedCertificate -DnsName "localhost", "localhost" -CertStoreLocation "cert:\LocalMachine\My" when you execute is gonna generate the thumbprint of certificate keep to associate to the port something like this "B80BE75765AA5739EAC63AAF67C32E5A3625FF19"
in window type "certificates" and click manage computer certificates and copy the certificate from personal\certificates to trusted root certification authorities\certificates
associate the certificate hash (thumbprint to the port) - netsh http add sslcert ipport=0.0.0.0:{0} certhash={1} appid={2} certstore=MY 0 - port - 1 - (the thumbprint generated by the certificate) 2 - {555b2e5f-4877-459b-bff2-60bb25898455} (GUID)

Related

HTTP Windows Service to HTTPS

I have a windows service that hosts my wcf service.
The app.config is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
<system.serviceModel>
<services>
<service behaviorConfiguration="RestWCFServiceLibrary.Service1Behavior" name="RestWCFServiceLibrary.RestWCFServiceLibrary">
<endpoint address="" binding="webHttpBinding" contract="RestWCFServiceLibrary.IRestWCFServiceLibrary" behaviorConfiguration="web">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8888/RestWCFServiceLibrary/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RestWCFServiceLibrary.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
<CorsSupport/>
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="CorsSupport" type="WebHttpCors.CorsSupportBehaviorElement, WebHttpCors, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
</configuration>
My problem is that if I have my website using https:// it fails to make the http call because of CORS. The https website makes an ajax GET request to the localhost.
Now I am trying to change my windows service to https but everywhere I see some command line ssl bindings. Is there a different way I can change my wcf self hosted windows service to use https?
What do I need to do in order to get this http service migrated over to https.
Please provide example of what needs to be modified in my app.config.
I stumbled upon similar problem so what i did was used WCF Configuration tool to write a App.Config for me and inside endpoints I selected mexhttpsbinding and yaa the https binding worked..
Let's just add an https endpoint. The following configuration works properly over both http and https.
<system.serviceModel>
<services>
<service behaviorConfiguration="mybehavior" name="WcfService1.Service1">
<endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webbev"></endpoint>
<endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webbev" bindingConfiguration="myhttpsbinding"></endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:11010"/>
<add baseAddress="https://localhost:11011"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="myhttpsbinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:10:00" receiveTimeout="00:10:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="mybehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webbev">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
Since https protocol is protected by the certificate, we are supposed to bind the certificate to the https port for https endpoint. (we could specify the certificate in IIS binding module instead of CMD if hosting the service in IIS)
netsh http add sslcert ipport=0.0.0.0:11011 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00112233-4455-6677-8899-AABBCCDDEEFF}
Execute CMD with administrator privileges and ensure that the certificate is installed on the local machine certificate store (certlm.msc). Certhash parameter specifies the thumbprint of the certificate. The appid parameter is a GUID that can be used to identify the owning application(located in the project.csproj file)
<ProjectGuid>{56FDE5B9-3821-49DB-82D3-9DCE376D950A}</ProjectGuid>
https://learn.microsoft.com/en-us/windows/desktop/http/add-sslcert
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-a-port-with-an-ssl-certificate
Feel free to contact me if there is anything I can help with.
Https only works on port 443. so you better have your virtual host created in your SSL script tag in your server configuration.
Or you can also proxy pass your request http:// port(8888) to https:// (port:443)

Windows Service hosting WCF service can only be accessed by my domain user

I had developed a windows service that hosts a WCF service. The service is installed on a server and the idea is to process some files on the local network (domain). Also, the service is executing as my domain user.
the configuration of the service is this:
<system.serviceModel>
<services>
<service name="Zeus.My.Upload.Service.MyHostedService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:1089/Domain/Service"/>
</baseAddresses>
</host>
<endpoint address="http://localhost:1089/Domain/Service/Uploader" binding="basicHttpBinding" contract="Zeus.My.Upload.Contract.IHostedService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="4294967296" transferMode="Streamed" sendTimeout="01:00:00" messageEncoding="Mtom">
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
The issue with this configuration is that only my user is able to access and use this service. Other users of domain cannot even access to the URL.
How can I solve this issue?

WCF service reject with error The server has rejected the client credentials

Following this guide i try to Host WCF service in a Windows Service Using TCP.
this works fine on my computer but when install this service in other computer in the same network got an error: The server has rejected the client credentials
I try to disable Firewall but still same error (and the service running...)
from the client side Add service reference works fine and recognize the service.
this is my app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://192.168.0.100:8523/Service1 " />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
192.168.0.100 is the server machine IP address.
Try to use this config for tcp binding:
<bindings>
<netTcpBinding>
<binding name="customTcpBinding" maxReceivedMessageSize="20480000" transferMode="Streamed" >
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>

I couldn't properly publish duplex wcf service

I am trying to publish my duplex wcf service on a server with no success, I am able to publish it on local IIS, but when I publish it to server its address become net.tcp://win-rhkt30stjd7/Broadcastor/BroadcasterService.svc. As you would agree such address is not useful at all while creating the service reference on client. I tried to publish it as WCF application project, and service library project but both is giving the same result. Probably something is missing from my Web.config file but I don't know what it is. Please help me out here. Below is my Web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="false" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<services>
<service name="BroadcastorServiceApp.BroadcastorService">
<endpoint binding="netTcpBinding" contract="BroadcastorServiceApp.IBroadcastorService">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<netTcpBinding>
<binding>
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
I dont see any address part in your NET TCP endpoint
1 : Add a base address as below :
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8088" />
</baseAddresses>
</host>
2 : add an address parameter to your net tcp endpoint as :
<endpoint address = "tcpEndPoint"
binding="netTcpBinding"
contract="BroadcastorServiceApp.IBroadcastorService"></endpoint>
3 : Alse give a behavior name as :
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
And add it to the service like :
<service name="BroadcastorServiceApp.BroadcastorService" behaviorConfiguration="ServiceBehavior">
<endpoint binding="netTcpBinding" contract="BroadcastorServiceApp.IBroadcastorService"></endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>

wcf dual channel error

I have a wcf service that users can chat trough it.
when I test it in local IIS it works, but when publish it in external server, and call a method, it throws:
Security negotiation failed because the remote party did not send back
a reply in a timely manner. This may be because the underlying
transport connection was aborted.
webconfig.conf
....
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="bind" textEncoding="utf-8">
<security mode="None" />
</binding>
</wsDualHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="svcbh">
<serviceMetadata httpGetEnabled="False" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="QasedakServer.QasedakAPI" behaviorConfiguration="svcbh">
<host>
<baseAddresses>
<add baseAddress="http://www.mywebsite.com/" />
</baseAddresses>
</host>
<endpoint name="duplexendpoint" address="" binding="wsDualHttpBinding" contract="QasedakServer.IQasedakAPI" bindingConfiguration="bind" />
<endpoint name="MetaDataTcpEndpoint" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
....
my program uses dual channel mode connection.
plz help me.

Categories

Resources