提供的URI方案'net.tcp'无效;预期'http'

时间:2012-01-13 00:25:09

标签: c# wcf

我是WCF的新手。我正在尝试编辑现有代码以使用net.tcp绑定而不是http绑定。我在使用配置文件的测试项目中很容易做到这一点,但由于各种原因,在实际项目中它以编程方式完成。

我进行了必要的更改,服务主机似乎正确启动:

 Uri baseAdress= new Uri("net.tcp://localhost:7005/MyService/");
 host = new ServiceHost(typeof(MyServiceImpl), baseAdress);

 host.AddServiceEndpoint(
              typeof(MyService),
              new NetTcpBinding(),
              "");

 ServiceMetadataBehavior metadataBehavior;
 metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();

 if (metadataBehavior == null)
 {
      metadataBehavior = new ServiceMetadataBehavior();
      host.Description.Behaviors.Add(metadataBehavior);
 }

 BindingElement bindingElement = new TcpTransportBindingElement();
 CustomBinding binding = new CustomBinding(bindingElement);
 host.AddServiceEndpoint(typeof(IMetadataExchange), binding, "mex");

 host.Open();

到目前为止一切顺利。我编辑了连接字符串客户端:

 string serverUri = string.Format("net.tcp://{0}:{1}/MyService", serverName, port);
 MyService server = new MyServiceClient("MYS", serverUri);

但是当我尝试从我的服务中调用函数时,我收到此错误:

  

提供的URI方案'net.tcp'无效;预期'http'

不太确定我错过了什么......有什么提示吗?

0 个答案:

没有答案