本文介绍了只能将绝对URI用作基地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请在下面的代码中的using (ServiceHost host = new ServiceHost(typeof(HelloService.HelloService)))
处获取异常
Please help getting exception at using (ServiceHost host = new ServiceHost(typeof(HelloService.HelloService)))
in the below code
WCF主机应用程序
class Program
{
static void Main()
{
using (ServiceHost host = new ServiceHost(typeof(HelloService.HelloService)))
{
host.Open();
Console.WriteLine("Service Started");
Console.ReadLine();
}
}
}
合同执行
public class HelloService : IHelloService
{
public string GetMessage(string Name)
{
return "Hello" + Name;
}
}
合同
[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>
推荐答案
我相信您缺少一个冒号(:
):
I believe you are missing a colon (:
):
<add baseAddress="net.tcp//localhost:8090/HelloService"/>
应该是
<add baseAddress="net.tcp://localhost:8090/HelloService"/>
这篇关于只能将绝对URI用作基地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!