Only an absolute URI can be used as a base address
Asked Answered
C

3

6

Please help getting exception at using (ServiceHost host = new ServiceHost(typeof(HelloService.HelloService))) in the below code

Exception : Only an absolute URI can be used as a base address

WCF Host Application

    class Program
    {
        static void Main()
        {
            using (ServiceHost host = new ServiceHost(typeof(HelloService.HelloService)))
            {
                host.Open();
                Console.WriteLine("Service Started");
                Console.ReadLine();
            }
        }
    }

Contract Implementation

    public class HelloService : IHelloService
    {
        public string GetMessage(string Name)
        {
            return "Hello" + Name;
        }
    }

Contract

[ServiceContract]
    public interface IHelloService
    {
        [OperationContract]
        string GetMessage(string Name);
    }

App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="HelloService.HelloService" behaviorConfiguration="mexBehaviour">
        <endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService">
        </endpoint>
        <endpoint address="HelloService" binding="netTcpBinding" contract="HelloService.IHelloService">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/HelloService"/>
            <add baseAddress="net.tcp//localhost:8090/HelloService"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
Cash answered 12/6, 2015 at 18:32 Comment(2)
Do you know what a URI is? Do you know what an absolute URI is? Do you see any URIs in what you posted? Are any of them not absolute? Pay especial attention to any which are base addresses.Imperceptible
just encountered with same problem from kudVenkat tutorials. thanks to your question.Lithoid
I
7

I believe you are missing a colon (:):

<add baseAddress="net.tcp//localhost:8090/HelloService"/>

should be

<add baseAddress="net.tcp://localhost:8090/HelloService"/>
Imperceptible answered 12/6, 2015 at 21:6 Comment(0)
W
1
<endpoint address="HelloService"...

Should be

<endpoint address="/HelloService"...

See https://msdn.microsoft.com/en-us/library/ms733749(v=vs.110).aspx

Windywindzer answered 12/6, 2015 at 19:4 Comment(3)
Do I need to write endpoint address="/HelloService" and baseAddress="localhost:8080"Cash
Yes I believe so, although you should be able to specify the http or the net.tcp.Windywindzer
I think it takes baseaddress + endpoint address as absolute address...so in my case it will be localhost:8080/HelloService but its not workingCash
N
0

In short this is Error related to base address.so, please check whether you have entered base address properly or not.

Error:

<add baseAddress=" &quot;http://localhost:8732/Design_Time_Addresses/WcfServiceLibraryShop/IStudent/&quot;&gt;" />

Solved:

<add baseAddress=" http://localhost:8732/Design_Time_Addresses/WcfServiceLibraryShop/IStudent/" />
Narco answered 4/10, 2018 at 19:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.