WCF 身份验证和套接字中止异常
这是该项目的设置。
我有一个 WCF 服务,以缓冲模式托管在 net.tcp 绑定上,并启用了 ReliableSession。
绑定配置为使用 TransportWithMessageCredential 安全性。该证书是我使用指纹识别的自签名证书。 UserNameValidator 是一个自定义验证器,用于测试,永远不会失败(之前没有失败,但我消除了不确定性)
服务和客户端位于同一台计算机上,并且它们都可以访问证书。
问题:
当我尝试从服务中使用方法时,我收到了 Socket Aborted 异常。这是我用来打开服务连接的代码。 MonitorServiceCallbacks 仅包含空方法来满足接口的要求。
_instanceContext = new InstanceContext(new MonitorServiceCallbacks());
_serviceInterface = new MonitorCallbackServiceClient(_instanceContext);
_serviceInterface.ClientCredentials.UserName.UserName = Environment.MachineName;
_serviceInterface.ClientCredentials.UserName.Password = "myPassword";
_serviceInterface.Open();
这似乎工作正常,因为 _serviceInterface.State 变量设置为 State.Opened 并且调用自定义验证器并毫无例外地返回。
但是,如果我尝试使用 _serviceInterface 代理调用方法,则该服务上不会运行我可以闯入的代码,并且除了 SocketAborted 异常之外,跟踪日志不会显示任何错误,该异常在收到似乎是以下消息后 1 分钟发生的方法。
没有内部异常。
我尝试用谷歌搜索这个问题,但结果往往是“只要禁用安全性,它就会正常工作”。不幸的是,这无法做到。
我对这个问题感到非常困惑,任何帮助将不胜感激。
非常感谢,
埃里斯
here's the setup for the project.
I have a WCF Service that is hosted on a net.tcp binding in buffered mode and ReliableSession enabled.
The binding is configured to use TransportWithMessageCredential security. The certificate is a self signed certificate that I am identifying using the Thumbprint.
The UserNameValidator is a custom validator which for testing, never fails (it wasn't failing before but I removed the uncertainty)
The service and client are on the same machine and they both have access to the certificate.
The problem:
I am receiving a Socket Aborted exception when trying to consume a Method from the service. Here is the code I use to open a connection to the service. MonitorServiceCallbacks only contains empty methods to fulfil the requirements of the Interface.
_instanceContext = new InstanceContext(new MonitorServiceCallbacks());
_serviceInterface = new MonitorCallbackServiceClient(_instanceContext);
_serviceInterface.ClientCredentials.UserName.UserName = Environment.MachineName;
_serviceInterface.ClientCredentials.UserName.Password = "myPassword";
_serviceInterface.Open();
This appears to work fine as the _serviceInterface.State variable is set to State.Opened and the custom validator is called and returns without exception.
However, if I try to call a method using the _serviceInterface proxy, no code that I can break into is run on the service and the tracelog reveals no errors apart from a SocketAborted exception which occurs 1 minute after receiving what appears to be the message for the method.
There is no InnerException.
I have tried to google the issue but the results tend to say "just disable security and it will work fine". Unfortunately, this cannot be done.
I am extremely confused by this issue and any help would be greatly appreciated.
Many thanks,
Ehrys
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上是一个序列化错误。
我试图发送到从数据协定继承的服务的对象。所以我试图将数据契约的转换发送到服务。
WCF 似乎不允许这样做。
我要感谢 John Saunders 提醒我,不仅服务可以启用跟踪。启用客户端跟踪会节省我很多时间。
我试图做以下事情:
我需要做什么:
This was actually a serialisation error.
The object I was trying to send to the service inherited from the data contract. So I was trying to send a cast down to the data contract to the service.
WCF doesn't appear to allow this.
I would like to thank John Saunders for reminding me that not only the service can have tracing enabled. Enabling client side tracing would have saved me a lot of time.
I was attempting to do the following:
What I needed to do: