Attilah Attilah - 2 months ago 6
C# Question

Invalid Operation Exception

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.


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:

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

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:

    <behavior name="Default">
           httpGetUrl="http://localhost:8282/YourService/mex" />

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.