找不到具有绑定 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);




本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

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

会员中心
搜索
«    2025年11月    »
12
3456789
10111213141516
17181920212223
24252627282930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864