24 December 2010

WCF Not Using My Domain Name, But Rather My Computer Name When Viewing MyService.Svc?Wsdl

HOWTO: Fix WCF Host Name on IIS
By gavinmckay
This is a problem I have tripped across before, and it just popped up again. Time for a post on how to fix it, mainly so I won’t have to track down MSDN articles and obscure posts to remember how to do it!

When building a WCF Web Service on your local machine, the service will automatically generate WSDL for you with an address similar to http://YOURPC/MyService.svc. This works fine when testing locally, but when you want to publish this to your production environment so it can be used by World + Dog, it doesn’t respect the fact you have a nice URL you would like to use instead. For example, if your production server is “Server01″ and the URL you have assigned to the website in IIS is my.publicserver.com, your service may look like this:


Instead of displaying the “real” URL (my.publicserver.com), it displays the name of the server (server01) instead. Not at all what is required! Worse still, connections to your web server will fail because the WSDL is pointing to the non-published server name and your client won’t be able to get there. This is because WCF automatically uses the IIS Site Bindings to determine what the base addresses for the service should be.

The solution is to update the IIS metabase so IIS knows what to do with the request, then WCF will pick up on this. To fix this, perform the following steps.

Get the Website Identifier from IIS

To change the site bindings you need to know which site to change. Open the IIS Manager to view the sites available, find the one you want to change, and record the website id in the “Identifier” column. You will need this in the next step.
.....


Copied from gavin mckey blog

The page you are requesting cannot be served because of the extension configuration

Recently, I migrated to Windows 7 and ended up installing all my software's again. I had a project which involved hosting a WCF service on IIS. The service used a .svc file extension and IIS 7 on my machine was not aware how to handle these files.

The error I got looked something like this:

HTTP Error 404.3 – Not Found

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map. Detailed Error InformationModule StaticFileModule.

There were more errors related to local machine below these errors.I looked up the net and after some digging figured out the solution to the problem:

Run Visual Studio 2008 Command Prompt as “Administrator”.
Navigate to C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation.
Run this command servicemodelreg –i.
The servicemodelreg is a command line tool which provides the ability to manage the registration on ServiceModel on a machine. You can get more info on the tool at MSDN here.

I guess the mistake I made was enabling IIS post installing VS and .NET 3.5 or else the services are not turned on for IIS 7.0 by default.

Copied from Rahul's blog