简体   繁体   English

WCF身份验证和套​​接字异常终止

[英]WCF Authentication and Socket Aborted Exception

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. 我有一个WCF服务,该服务以缓冲模式托管在net.tcp绑定上,并启用了ReliableSession。

The binding is configured to use TransportWithMessageCredential security. 绑定配置为使用TransportWithMessageCredential安全性。 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) UserNameValidator是用于测试的自定义验证器,它永远不会失败(之前并没有失败,但是我消除了不确定性)

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. 尝试从服务使用方法时,我收到了Socket Aborted异常。 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. MonitorServiceCallbacks仅包含满足接口要求的空方法。

 _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. 由于_serviceInterface.State变量设置为State.Opened且调用了自定义验证器,并且无异常返回,因此这似乎工作正常。

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. 但是,如果我尝试使用_serviceInterface代理调用方法,则该服务上不会运行任何我可以破解的代码,并且在收到看来是该消息的1分钟后,除了SocketAborted异常,tracelog不会显示任何错误。方法。

There is no InnerException. 没有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 埃里斯

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. WCF似乎不允许这样做。

I would like to thank John Saunders for reminding me that not only the service can have tracing enabled. 我要感谢John Saunders提醒我,不仅服务可以启用跟踪。 Enabling client side tracing would have saved me a lot of time. 启用客户端跟踪可以节省很多时间。

I was attempting to do the following: 我正在尝试执行以下操作:

_serviceInterface.Register((MyDataContract)MyParentObject, aVariable, anotherOne);

What I needed to do: 我需要做的是:

MyDataContract tempContract = MyParentObject.CreateMyDataContract();
_serviceInterface.Register(tempContract, aVariable, anotherOne);
/* Note: MyParentObject.CreateMyDataContract() is my own method which creates an instance
of the MyDataContract and copies the relevant information to it */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM