views:

374

answers:

2

When I publish my ASP.NET WCF service, the WSDL uses the machine name instead of the domain name. How to prevent this?

Example:

<wsdl:import namespace="http://ListenerService" 
     location="http://MACHINE_NAME/ListenerService/service.svc?wsdl=wsdl0"/&gt;
<soap:address location="http://MACHINE_NAME/ListenerService/service.svc"/&gt;

When I really want:

<wsdl:import namespace="http://ListenerService" 
     location="http://MYDOMAIN.COM/ListenerService/service.svc?wsdl=wsdl0"/&gt;
<soap:address location="http://MYDOMAIN.COM/ListenerService/service.svc"/&gt;
+2  A: 

You cannot prevent this from happening - at least not just with a config switch or something like that.

You might be able to fix your problem by looking at this article here - a chap describing the exact problem you encounter and a possible fix to it:

http://www.codemeit.com/wcf/wcf-wsdl-xsdimport-schemalocations-link-to-local-machine-name-not-domain-name-while-hosted-in-iis.html

And another smart gentleman who ran into a few problems with the same issue:

http://www.leastprivilege.com/HostHeadersSSLAndWCFMetadata.aspx

Marc

marc_s
+1  A: 

Just so that future visitors discover the right answer to this question: the above commenter is not correct. You can fix this problem by changing several options in the web.config. Here is how mine is set up:

<system.serviceModel>
    <services>
      <service name="ourWebService.ourService" behaviorConfiguration="ourWebService.ourServiceBehavior">
    <host>
            <baseAddresses>
                <add baseAddress="http://oursitename.com:83/ourService.svc" />
            </baseAddresses>
        </host>
        <endpoint bindingNamespace="http://oursitename.com:83/ourService.svc" 
        address="" binding="basicHttpBinding" contract="ourIWebService.IourService" 
        bindingConfiguration="customBinding2">
          <identity>
            <dns value="oursitename.com" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
    <basicHttpBinding>
        <binding name="customBinding2" >
          <readerQuotas maxArrayLength="2147483" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ourWebService.ourServiceBehavior" httpGetUrl="http://oursitename.com:83/ourService.svc"&gt;
          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://oursitename.com:83/ourService.svc/mex"/&gt;
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

The important bits are the get urls, the identity, and the baseAddresses.

Sharon