WCF: relativeAddress,baseAddress and binding

16,260

Solution 1

MSDN http://msdn.microsoft.com/en-us/library/ms733749.aspx: *

There are two ways to specify endpoint addresses for a service in WCF. You can specify an absolute address for each endpoint associated with the service or you can provide a base address for the ServiceHost of a service and then specify an address for each endpoint associated with this service that is defined relative to this base address. You can use each of these procedures to specify the endpoint addresses for a service in either configuration or code. If you do not specify a relative address, the service uses the base address.

* So according to your example you have base adress

 http://localhost:18148/

and it will be combined with RelativeAddress.svc, as a name of your svc file. And then it will try to combine this string with /RelativeAddressX.svc as a part of endpoint adress. So you will have something like

 http://localhost:18148/RelativeAddress.svc/RelativeAddressX.svc. 

Your endpoint must not specify the path to svc in IIS. It should containg only a logical adress, assosiated with this point. So try to change your endpoint to the following:

 <endpoint  address="RelativeAddressX" binding="basicHttpBinding" contract="WCF_Transactions.IService1"></endpoint>

And it should be accessible by the path

 http://localhost:18148/RelativeAddress.svc/RelativeAddressX

Solution 2

You don't need to specify in the config file when hosting in IIS or Cassini - the base URL is provided by the web server. The element is used when self-hosting. Cassini (VS build in web-server) will ignore it.

Here is a good page about WCF addressing: http://msdn.microsoft.com/en-us/magazine/cc163412.aspx

Here are some related posts: WCF Service Endpoints vs Host Base address WCF, changing the baseAdress of an endpoint

Share:
16,260
NET
Author by

NET

Updated on June 04, 2022

Comments

  • NET
    NET almost 2 years

    I am new in WCF and start my experience with a simple file-less application part of which (web.config) you can see below:

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
            <serviceActivations>
                <add
                    factory="System.ServiceModel.Activation.ServiceHostFactory"
                    relativeAddress="./RelativeAddress.svc"
                    service="WCF_Transactions.MyService1"/>
            </serviceActivations>
        </serviceHostingEnvironment>
    

    Now I can access service at

    http://localhost:18148/RelativeAddress.svc
    

    Then I add next lines:

        <services>
            <service name="WCF_Transactions.MyService1" behaviorConfiguration="MyBehavior1">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:18148/" />
                    </baseAddresses>
                </host>
                <endpoint  address="/RelativeAddressX.svc" binding="basicHttpBinding" contract="WCF_Transactions.IService1"></endpoint>
            </service>
        </services>
    
        <behaviors>
            <serviceBehaviors>
                <behavior name="MyBehavior1">
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    

    So I expect that my service could be accessible through next address:

      http://localhost:18148/RelativeAddressX.svc
    

    but I can't do this. What have I misunderstood?