少有人走的路

勇哥的工业自动化技术网站

找不到具有绑定 NetTcpBinding 的终结点的与方案 net.tcp 匹配的基址。注册的基址方案是 []

勇哥注:

这个问题有些奇怪,虽然被AI解决了(还是引导数次才总算得到正确的方式)

但是我清楚的记得下面的问题代码先前是正确的,为啥现在不灵了?

AI说的办法,还真是个知识的盲区,之前一直以为指定基地址应该是在host open的时候,

也就是这个wcf函数,ServiceHost(Type serviceType, params Uri[] baseAddresses)。



问题代码:

  NetTcpBinding wsbind13 = new NetTcpBinding();
  if (isok)
  {
     wsbind13.Name = "wsbind1";
     wsbind13.ReceiveTimeout = GetReceiveTiemout(1);
     wsbind13.ReliableSession.Enabled = true;
     wsbind13.Security.Mode = SecurityMode.None;
  }

  host1 = new ServiceHost(typeof(MotionCardRes.SharePublishMessageService));
  host1.AddServiceEndpoint(typeof(ISharePublishMessage), wsbind13/*new WSHttpBinding()*/,  
      $"net tcp://{IpAddress}:{ConfigurationManager.AppSettings["SharePublishMessageService"]}/ISharePublishMessage");

正确写法:

  NetTcpBinding wsbind13 = new NetTcpBinding();
  if (isok)
  {
     wsbind13.Name = "wsbind1";
     wsbind13.ReceiveTimeout = GetReceiveTiemout(1);
     wsbind13.ReliableSession.Enabled = true;
     wsbind13.Security.Mode = SecurityMode.None;
  }

  //构建完整的基址并添加到终结点地址中  
  Uri baseAddress = new Uri($"net.tcp://{IpAddress}:{ConfigurationManager.AppSettings["SharePublishMessageService"]}");
  string endpointAddress = baseAddress.AbsoluteUri + "/ISharePublishMessage"; // 如果需要额外的路径段  


  host1 = new ServiceHost(typeof(MotionCardRes.SharePublishMessageService));
  host1.AddServiceEndpoint(typeof(ISharePublishMessage), wsbind13/*new WSHttpBinding()*/, endpointAddress);




发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

«    2026年1月    »
1234
567891011
12131415161718
19202122232425
262728293031
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接

Powered By Z-BlogPHP 1.7.3

Copyright www.skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864