只有绝对URI可以用作基址

Bhu*_*dey 5 .net c# asp.net wcf contracts

using (ServiceHost host = new ServiceHost(typeof(HelloService.HelloService)))在下面的代码中帮助获得例外

例外:只有绝对URI可用作基址

WCF主机应用程序

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

合同执行

    public class HelloService : IHelloService
    {
        public string GetMessage(string Name)
        {
            return "Hello" + Name;
        }
    }
Run Code Online (Sandbox Code Playgroud)

合同

[ServiceContract]
    public interface IHelloService
    {
        [OperationContract]
        string GetMessage(string Name);
    }
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

Joh*_*ers 5

我相信你错过了冒号(:):

<add baseAddress="net.tcp//localhost:8090/HelloService"/>
Run Code Online (Sandbox Code Playgroud)

应该

<add baseAddress="net.tcp://localhost:8090/HelloService"/>
Run Code Online (Sandbox Code Playgroud)