c# - 只有绝对 URI 可以用作基地址

标签 c# asp.net .net wcf contracts

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

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

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/

相关文章:

.net - 创建 Shiny 的图形/光泽效果

c# - 无法将 json 转换为对象

c# - Automapper 中缺少类型映射配置或不支持的映射错误

c# - Paypal 错误从 Asp.net 中的传输流接收到意外的 EOF 或 0 字节

c# - 如何从 ASP.NET 获取网页的 HTML 内容

c# - 动态创建的按钮单击事件在 asp.net c# 中不起作用

asp.net - asp.net 应用程序中的内存泄漏 - W3WP 和 gen 2 堆持续增长,直到 AppPool 回收

c# - 如何让 "Copy to Output Directory"与单元测试一起使用?

c# - HttpClient 不断收到错误请求

c# - 使用 C# Math.Abs​​ 返回值 - 未获得预期输出