views:

477

answers:

2

I have a WCF service that is hosted in IIS on a public web server, and needs to be discoverable.

Thing is, when I browse http://myserver.mydomain/myfolder/myService.svc, the page that is displayed shows the actual machine name instead of the URL I provided, e.g. http://myRealServer.myRealDomain/myFolder/myService.svc?wsdl as the link to view the WSDL.

Similarly, if I connect to the service through a tool such as soapUI, the links to the additional "wsdl0" outputs etc. are provided with the real server details instead of the URL I provide (thus making the service undiscoverable).

My question: How do I change this URL to display correctly?

Note: My development environment uses IIS6 on Win2003, the live environment is IIS7 on Win2008, the problem occurs in both environments.

A: 

What you could do is provide a static WSDL which you can tweak and modify to your liking, before making it available.

In that case, the static WSDL is supplied "as is", instead of querying the actual running service to create the WSDL "on the fly". This can also be a performance boost.

In order to do this, you need to specify the name and location of the WSDL file like this:

<system.serviceModel>
   <behaviors>
      <serviceBehaviors>
        <behavior name="StaticWsdl">
          <serviceMetadata httpGetEnabled="true" 
               externalMetadataLocation="http://localhost:8000/YourService/YourWSDL.wsdl"/&gt;
        </behavior>
      </serviceBehaviors>
   </behaviors>

Now, whenever a request for the WSDL or Metadata comes in, this static WSDL will be provided instead.

This also allows you to create a single WSDL which contains all necessary information, including the XML schema for the data being passed around. No more importing or referencing external WSDL or XSD fragments.

Marc

marc_s
@marc_s: isn't this just the normal IIS host header issue? In the absence of a host header for the outside name, it uses the machine name?
John Saunders
@John: not sure - I'm not familiar with that particular issue (since I never host in IIS myself)
marc_s
@marc_s I have tried adding this and it makes no difference.
Martin Robins
@marc_s: I will bear this option in mind, but I would prefer to stick with the dynamic generation of the wsdl if I can.
Martin Robins
@Martin: sure - just another option to bear in mind - just in case :-)
marc_s
@Martin - This sounds exactly like the host header issue to me. I'd double check that.
DanO
+1  A: 

Not sure about IIS7 (although I'm sure it must be possible), but with IIS6 you can set up a Host Header for a website. Setting this to "myserver.mydomain" could sort things out. See http://stackoverflow.com/questions/1078894/generated-wcf-proxy-configuration-uses-servers-local-name/.

Graham Clark
@Partario: I tried adding a host header to the site, but it continues to display the actual machine name rather than the host header value provided. Thanks though.
Martin Robins