2

I have the following configuration file for WCF service. There is a host defined in the config. Still, when I print the service address from the client, it does not know about the host. The printed result is:

http://localhost:3187/Service1.svc/MyFolder

Why doesn’t it take into account the host name? What modification do we need to do for it?

Note: I am running from VS 2010 for running service and client website.

        Service1Client myClientService = new Service1Client();
        Response.Write(myClientService.Endpoint.Address);

Client Configuration (Autogenerated by Visual Studio)

    <client>
  <endpoint address="http://localhost:3187/Service1.svc/MyFolder"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
    contract="MyWCFReference.IService1" name="WSHttpBinding_IService1">
    <identity>
      <userPrincipalName value="U16990@ustr.com" />
    </identity>
  </endpoint>
</client>

The server side configuration is:

<services>

  <!--MyService-->
  <service name="MyWCFServiceApplication.MyService"
           behaviorConfiguration="WeatherServiceBehavior">

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:80/ServiceModelSamples/FreeServiceWorld"/>
      </baseAddresses>
    </host>

    <endpoint address="MyFolder"
              binding="wsHttpBinding"
              contract="MyWCFServiceApplication.IService1" />

    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
  </service>

</services>


  <behaviors>

  <serviceBehaviors>

    <behavior name="WeatherServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="False"/>
    </behavior>

  </serviceBehaviors>

</behaviors>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

LCJ
  • 22,196
  • 67
  • 260
  • 418
  • The host address is ignored http://stackoverflow.com/questions/56249/wcf-service-configuration-file-question-regarding-baseaddresses – msmucker0527 Dec 06 '11 at 14:19

2 Answers2

2

When a WCF service is hosted in an ASP.NET process, through either IIS or the ASP.NET Development Server (a.k.a Cassini), the baseAddresses setting in the service's configuration file is ignored since the service will always be reachable through the URL of the SVC file.

The URL you're seeing on the client is therefore correct:

http://localhost:3187/Service1.svc/MyFolder

As you can see, the base address of the service becomes the URL of the SVC file on the web server.

Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
1

You're talking about a WCF client - yet, the config you posted only contains config for a service (the server side) ... (the <services> section).

I can't see any client configuration in what you posted - there ought to be a <client> section in your config somewhere

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Updated the post with (Autogenerated by Visual Studio) – LCJ Dec 06 '11 at 15:08
  • 1
    @Lijo: so that service is running hosted in IIS, on the same machine? Then yes - WCF will use `localhost` - I don't think there's anything you can do to change this. Why is this a problem for you?? – marc_s Dec 06 '11 at 15:17
  • 1
    I am using Visual Studio for hosting the service. Afterwards I need to move it on to a different server and need to install it in IIS 7. >>> This is not a problem..I want to understand the behavior. This knowledge is needed for me to host in IIS in different server. – LCJ Dec 06 '11 at 15:23
  • @Lijo The `baseAddresses` configuration setting is ignored when hosting a WCF service in IIS. See my answer for more details. – Enrico Campidoglio Dec 06 '11 at 15:34
  • 1
    @Lijo: if you host in the VS web server (Cassini), you will always see `localhost` used - Cassini doesn't support anything else (only works for local connections). If you move your service to a "real" server, then if you define your client, you'll need to use the "real" server's name (or IP address) to define the location of the service – marc_s Dec 06 '11 at 15:35