32

My WCF serice seems to be using the computer-name instead of the domain name. When I view the MyService.svc?wsdl link it is showing my computer name.

Where do I add my domain name in the web.config? Endpoint address, baseaddress or identity?

Note: I am using SSL so it has to be https://www.example.com/myservice.svc

symbiont
  • 1,428
  • 3
  • 21
  • 27
Blankman
  • 259,732
  • 324
  • 769
  • 1,199

13 Answers13

27

WCF 4.0 has solved this issue in some instances with a new config option that use Request Headers:

    <behaviors>
        <serviceBehaviors>
            <behavior name="AutoVaultUploadBehavior">
                <useRequestHeadersForMetadataAddress>
                    <defaultPorts>
                        <add scheme="https" port="443" />
                    </defaultPorts>
                </useRequestHeadersForMetadataAddress>
nick_alot
  • 2,982
  • 5
  • 30
  • 32
9

For IIS7 you don't add it to web.config, but to the IIS configuration file.

First off edit the bindings for your web site so the HTTP protocol specifies a host name if you haven't already - this will ensure it gets the correct name under HTTP.

Navigate to C:\Windows\System32\inetsrv\config and open applicationHost.config

Look for the sites section. You will see something like the following

<sites>
  <site name="Default Web Site" id="1">
    <application path="/">
        <virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
    </application>
    <bindings>
      <binding protocol="http" bindingInformation="*:80:puck" />
      <binding protocol="net.tcp" bindingInformation="808:*" />
      <binding protocol="net.pipe" bindingInformation="*" />
      <binding protocol="net.msmq" bindingInformation="localhost" />
      <binding protocol="msmq.formatname" bindingInformation="localhost" />
      <binding protocol="http" bindingInformation="*:80:puck.idunno.org" />
      <binding protocol="http" bindingInformation="*:80:localhost" />
      <binding protocol="https" bindingInformation="*:443:" />
    </bindings>
  </site>
  ....
</sites>

You can see that the bindings for the http protocol specify a host header, but https doesn't. When you're web browsing you can't use host headers over HTTPS, but WCF still uses it when generating the WSDL - if it can't find one it will fall back to the machine name.

So all you need to do is edit the HTTPS binding like so

      <binding protocol="https" bindingInformation="*:443:puck" />

appending the correct FQDN to the end of the binding information. Reset IIS and WCF should get it right now.

The IIS6 solution has already been posted by darin

blowdart
  • 55,577
  • 12
  • 114
  • 149
  • This works, but I run into a problem only the exact domain name I specify will work. For example if I do: *:443:domain.com Then only domain.com/Service.svc will work, if I do: *:443:www.domain.com Then only www.domain.com/Service.svc will work, but not both. How can I get both? (With https prefix) – test Jun 30 '12 at 20:28
8

As stated in this link WCF is using the computer name instead of the IP address and cannot be resolved

It solved my problem, maybe because i have multiple web sites in the same host, and is very simple.

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
cyberop5
  • 187
  • 2
  • 7
Pedro Dias
  • 81
  • 1
  • 4
4

To fix this problem Configure the httpGetEnabled attribute and httpsGetEnabled attribute in web.config file

<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
User0106
  • 519
  • 1
  • 5
  • 13
  • Simple, easy, exactly what is needed. Don't know why everyone else is suggesting all these other complicated solutions. This does exactly what the OP wants. – Steve May 28 '13 at 16:48
  • That was the cincher for me! Thanks @Haridharan – Rob Koch Jan 10 '14 at 14:55
3

We're using WCFExtras to change the name of the host.

WCFExtras is a small open source library that will allow you to write the following to change the host name:

<behaviors>
  <endpointBehaviors>
    <behavior name="xxx">
      <wsdlExtensions location="http://some-hostname-visible-from-outside/path-to-a-service/service.svc" singleFile="True" />
    </behavior>
  ...
2

just adding <useRequestHeadersForMetadataAddress></useRequestHeadersForMetadataAddress> to the solved my issue. It seems that WCF 4.0 takes care of the Headers by adding this I was using SSL for accessing the WCF Service.

ABN
  • 21
  • 2
1

I have added solutions here, http://knowledgebaseworld.blogspot.com/2010/06/domain-name-replaced-with-machine-name.html. it should work for you all as its working fine with me on local, staging and production without doing binding on iis

IBhadelia
  • 291
  • 1
  • 5
1

None of these solutions were helpful to me. I was able to solve this with a very simple custom Service Factory.

Installing a WCF Service on a Shared Hosting Site, Revisited

Chris Marisic
  • 32,487
  • 24
  • 164
  • 258
1

Have you tried setting the host header in IIS?

Rebecca
  • 13,914
  • 10
  • 95
  • 136
1

Although its an old posting, here is an answer. Under Service Behaviour --> ServiceMetaData add service url.

Please note if you do not add myService, it will throw another error.

1

I had this very issue with my production server. I have found various articles on the multiple host headers with IIS and WCF issue, but if you are using SSL, you cannot add a host header to the website identities within the IIS UI, you can only add them to normal HTTP identities:

enter image description here

However you can add SSL host headers via a command prompt script, and this solved the issue for me:

cscript.exe adsutil.vbs set /w3svc/<site identifier>/SecureBindings ":443:<host header>"

For more information on this see this link: http://blumenthalit.net/blog/Lists/Posts/Post.aspx?ID=14

David Masters
  • 8,069
  • 2
  • 44
  • 75
0

Thanks to Kanasz Robert. Steps that solved my problem - 1.Produce the wsdl in the browser and save to file (by hitting .svc?wsdl from browser) save as .wsdl

  1. Produce the xsd files by hitting url from wsdl (xsd=xsd0, etc), and save to file from browser, save as .wsdl

  2. replace all machine name references from wsdl with domain name (or ip address) and change xsd references and save AND 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)

  3. copy wsdl and xsd file(s) to virtual directory add to your web.config following lines:

<behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://IPorDomainName/MyServices/FileTransferService.wsdl"  />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
subho
  • 79
  • 2
  • 12
0

This post solved it for me. I needed to associate my domain name with my IP address and website in IIS.

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

Shane
  • 875
  • 1
  • 6
  • 24