gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:06:42 27 4
gpt4 key购买 nike

请在下面的代码中使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com