Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / WCF

How to replace Machine Name with Domain name in WCF Service wsdl link

4.93/5 (15 votes)
14 Nov 2010CPOL 43.1K  
Today I was developing the application for streaming files on server using WCF. Everything was fine until I deployed application on production server. I found out that WCF was taking machine name instead of IP address or domain name. This accurs when WCF service is hosted on IIS. The links to wsdl use local machine name. The autogenerated page I received when I was navigating to the .svc page said:

svcutil.exe http://[machinename]/FileTransferService.svc


I discovered that it could be done by following steps:


  • Produce the wsdl in the browser and save to file (by hitting .svc?wsdl from browser)
  • Produce the xsd files by hitting url from wsdl (xsd=xsd0, etc), and save to file from browser
  • replace all machine name references from wsdl with domain name (or ip address) and change xsd references and save
  • replace all machine name references from xsd files with domain name (or ip address)
  • make sure to name xsd file with .xsd extension (ie, name0.xsd, name1.xsd, name2.xsd)
  • copy wsdl and xsd file(s) to virtual directory
  • add to your web.config following lines:

XML
<behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://IPorDomainName/MyServices/FileTransferService.wsdl"  />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)