How can I host 2 WCF self hosted services using different host names on the same machine (using the host header) - wcf

I'm trying to self host two WCF services with the following url conventions:
https://service.servicehost.com/service
https://service-branch.servicehost.com/service
And I get this error:
Service cannot be started.
System.ServiceModel.AddressAlreadyInUseException: HTTP could not
register URL https://+:443/service/. Another application has already
registered this URL with HTTP.SYS. --->
I understand the error and I know how to work it around by changing the service's suffix, but it seems like the WCF self host doesn't support the host header feature like IIS does (since I see the + sign).
Is there any way I can make it happen?

I'm not sure this can be done for SelfHost/Http. With Net.Tcp you would have had to use PortSharing to make this happen.
Worst case you could potentially create a Routing Service that routes your requests to the correct service, where each is listening on a different port.
Also, take a look at the documentation for HostNameComparisonMode Enumeration. The docs for basicHttpBinding will show you how to use it.

Related

wcf hosted in a windows service and httpbindings

I'm working on a wcf hosted inside a windows service. It works like a charm but now I need to reserve a specific hostname for this wcf just as IIS does.
To be more clear, my hosted wcf runs on a windows server machine which response to multiple dns name, but I need to let the wcf reachable only from one of these dns. If I was using IIS it would be achievable by setting a specific hostname within the http-bindings settings, but unfortunately, I can't manage my wcf like that.
To your knowledge, is there any way to reserve a specific hostname for a hosted wcf outside IIS?
Thanks in advance!
yes, you could do it by register the http endpoint at kernel level(http.sys) using the following commands
cmd: ***netsh http add urlacl url=http://fqdn:port/urlpath user=serviceaccount***
Then only on that specific dns/hostname, your http service will listen.

Fiddler Not Capturing WCF traffic but capturing ASMX fine

I have been capturing traffic using Fiddler for some ASMX services that call other ASMX services. In this case, I have a simple WCF service calling those ASMX services. It won't capture any traffic. The only wrinkle is that it is using IIS not IISExpress (http://localhost/Interface12Service/Interface12Service.svc). How can I capture WCF traffic?
The Microsoft .NET Framework is hardcoded to bypass proxies for any request to http://localhost. To capture such requests in Fiddler or any other proxy, use
http://machinename:port/
or
http://localhost.fiddler:port/
as the target URL.
By default, Fiddler will not capture the traffic. If you want it to capture the traffic, change the client proxy base address to your machine name or to your IP (for instance: 127.0.0.1). This should do the trick. If not, try this.
It could just be that fiddler has difficulty picking up traffic from localhost
Try changing the address to http://localhost./Interface12Service/Interface12Service.svc
(Notice the dot after localhost.) This is a common hack for working with Fiddler.
Another possible issue is related to WCF client (this may also include other clients but i'm not sure).
The client can be configured not to use the machine default proxy, which makes the client/application bypass Fiddler capture.
For further reading: What is the purpose of usedefaultwebproxy in WCF.

Why does my self-hosted WCF service take IIS offline?

As you may know, IIS 6+ can share port 80 with other HTTP applications running in different processes.
However my self-hosted WCF service seems to take IIS offline. When the WCF service is running, all HTTP requests go to the service. When I stop the service, all HTTP requests go to IIS. This is despite the fact that the two applications are using very unique URI paths. What's the deal? How do I get them to play together nicely?
EDIT:
My WCF service uses a custom binding with an HttpTransportBindingElement
Sorry if this belongs on serverfault. I'm not sure if it's a configuration issue or code issue.
After a lot more experimentation, I've come to a conclusion.
It looks like the problem is caused when the endpoint base address of the WCF service is the same as the base address of IIS. In other words if an endpoint exists at http://localhost/, it will take over and handle all incoming HTTP requests.
So even if your WCF subpaths are different from IIS, the base endpoint address has to be something other than http://localhost/.

how to configure fiddler to monitor wcf calls to a wcf services hosted in IISExpress

situation:
my website (which contains the WCF service) is hosted in IISExpres port number 58366 (http://localhost:58366/myapp)
I have a winforms client which connects to the wcf service using BasicHttpBinding
I want to debug my wcf calls using fiddler, but can't seem find how to redirect wcf calls through fiddler.
IISExpress idiotically binds to the hostname "localhost", not just to the port, so conventional workarounds as with adding a dot to the hostname don't work. Solution seems to be here. Note the last part of the selected answer: Use "localhost.fiddler" and Fiddler will emit "localhost" when proxying.
Rick Strahl has a good article on this here: http://www.west-wind.com/weblog/posts/2009/Jan/14/Monitoring-HTTP-Output-with-Fiddler-in-NET-HTTP-Clients-and-WCF-Proxies
Pretty sure a winforms app will usually pick up the default system proxy as set by fiddler. Are you operating on localhost? Try connecting to your machine name.

How to use Forms Auth when SSL is on a proxy in front of the IIS Farm (WCF)?

Here is my scenario:
I have a proxy that actually has the SSL Cert installed and this sits in front of a load balanced web farm. Each IIS server does not have SSL so I can't use transport security via wsHttp binding. I have not investigated basicHttp because we want to provide SOAP 1.2 going forward w/ this solution. In addition to this, my network team won't allow any use of certs to encrypt at the message level. (this alone would solve my dilemma i'm sure)
My security group has a requirement that we use Forms Authentication (membership provider).
The final solution must allow SSL via the front proxy, yet some type of WCF binding to keep complexity encapsulated in a config file.
I was working with a custom binding that allowed for username/password sent via clear text, but when I try to connect via https i get the usual "http expected" uri error.
How can I use SSL via the proxy to connect securely from client app to web service, but not have SSL installed on IIS and leverage the WCF stack + forms authentication?
I'm not new to WCF, but this very custom setup seems to have me unsure if the requirements allow for any type "easy" solution.
Thank you in advance!
EDIT: I did finally get this working and decided to write a short blog post with complete source code required to write the custom binding.
I think this is similar to a problem many have had when wanting to provide WCF services over SSL when the actual service in IIS is behind an SSL-offloading device. In which case, the following two pages should help you out:
http://blog.hackedbrain.com/archive/2006/09/26/5281.aspx
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/87a254c8-e9d1-4d4c-8f62-54eae497423f/
Basically you need to lie to WCF and say that the service is secure, even though the traffic will be conducted over HTTP (between the service and the proxy).