11

I created a WCF Serice that worked fine when hosted on IIS.

now, I took the same service, and created a host application in WPF, and when trying to start the service from that application, I get this exception :

The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the   
HttpGetUrl property is a relative address, but there is no http base address.  
Either     supply an http base address or set HttpGetUrl to an absolute address.
Attilah
  • 17,632
  • 38
  • 139
  • 202
  • what is your code to create the proxy ? – Dani Nov 01 '09 at 21:51
  • productsServiceHost = new ServiceHost(typeof(Products.ProductsService)); productsServiceHost.Open(); stop.IsEnabled = true; start.IsEnabled = false; status.Text = "Service running..."; – Attilah Nov 01 '09 at 22:00

3 Answers3

22

The error is quite clear - you're using HTTP, you have enabled HttpGetEnabled on your ServiceMetadata behavior, but you have not provided a base address in your config.

In IIS, base addresses are neither needed, nor used, since the location of the *.svc file defines your service address. When you're self-hosting, you can and should use base addresses.

Change your config to look something like this:

<system.serviceModel>
  <services>
    <service name="YourService">
      <host>
        <baseAddresses>
           <add baseAddress="http://localhost:8080/YourService" />
        </baseAddresses>
      </host>
      <endpoint address="mex" binding="mexHttpBinding"
                contract="IMetadataExchange" />
      ..... (your own other endpoints) ...........
    </service>
  </services>
</system.serviceModel>

Now, the "HttpGetEnabled" has a base address http://localhost.8080/YourService to go to to get the metadata from.

Or if you don't like this, again, the error message is quite clear on your alternative: define an absolute URL for the HttpGetUrl in your ServiceMetadata:

  <serviceBehaviors>
    <behavior name="Default">
      <serviceMetadata 
           httpGetEnabled="true" 
           httpGetUrl="http://localhost:8282/YourService/mex" />
    </behavior>
  </serviceBehaviors>

The clients can get your metadata from your "mex" endpoints, either at a fixed URL defined as in this second example, or they will go to the base address of the service for the metadata (if there is one).

If you're coming from IIS and haven't adapted anything, you'll have neither a base address, nor an explicit, absolute URL for your Metadata exchange endpoint, so that's why you get the error you're seeing.

Marc

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    I ended up here with the same problem, but not because I wasn't sure what to do. Rather, I didn't know what to look for to add a "base address" to my config. What resource did you use for determining the existence and syntax of the `` and `` properties? – Matt Jan 03 '16 at 00:12
0

I faced this error when I tried to use net.pipe binding.In my case, the default service behavior published the service metadata, This is the cause of my error. My solution is to use different behavior for your services. , then I changed my config file according to @marc_s answer and make different service behaviors as follows:

<serviceBehaviors>
        <!--Default behavior for all services (in my case net pipe binding)-->
        <behavior >

          <serviceMetadata   httpGetEnabled="false" httpsGetEnabled="false" />

          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <!--for my http services -->
        <behavior name="MyOtherServiceBehavior">

          <serviceMetadata   httpGetEnabled="true" httpsGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
Ali Fattahian
  • 495
  • 1
  • 6
  • 24
0

Check that the service class is correct.

It's solved my problem

// Create a ServiceHost for the CalculatorService type and 
// provide the base address.
serviceHost = new ServiceHost(typeof(ServiceClass));
Amir Touitou
  • 3,141
  • 1
  • 35
  • 31