勇哥注:
这个问题有些奇怪,虽然被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,转载请注明出处!讨论可扫码加群:



少有人走的路


















