请帮助在以下代码中的using (ServiceHost host = new ServiceHost(typeof(HelloService.HelloService)))处获取异常



WCF主机应用程序

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

契约(Contract)执行
    public class HelloService : IHelloService
    {
        public string GetMessage(string Name)
        {
            return "Hello" + Name;
        }
    }

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

应用配置
<?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>

最佳答案

我相信您缺少一个冒号(:):

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

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

关于c# - 只能将绝对URI用作基地址,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30809971/

10-11 22:17