简体   繁体   English

WCF代理仅在使用时出现故障

[英]WCF proxy gets faulted only on usage

I am learning WCF and trying out different examples from things learned in the book. 我正在学习WCF,并尝试从本书中学到的例子。

I have a simple service setup as follows: 我有一个简单的服务设置,如下所示:

[ServiceContract]
interface MyService
{
    [OperationContract(IsOneWay = true)]
    void Throws();
}

My client code is using the ChannelFactory class to create a proxy: 我的客户端代码使用ChannelFactory类创建代理:

var baseTcpAddress = new Uri("net.tcp://localhost/hello");

var tcpBinding = new NetTcpBinding();

// Create client channel.
ChannelFactory<ITestService> factory = new ChannelFactory<ITestService>(tcpBinding, new EndpointAddress(baseTcpAddress));
var channel = factory.CreateChannel();

var commObject = channel as ICommunicationObject;

commObject.Faulted += commObject_Faulted;
commObject.Closed += commObject_Closed;

When this method is called it throws an unhandled exception (not derived from FaultException), and a subsequent call using the same proxy throws an exception and the channel gets faulted. 调用此方法时,它将引发未处理的异常(不是从FaultException派生),并且随后使用相同代理的调用将引发异常,并且通道将出现故障。

The issue is i am registered on the Faulted event of the proxy channel, but i am not getting any notification, only when attempting to access the proxy. 问题是我已在代理通道的Faulted事件上注册,但是在尝试访问代理时我没有收到任何通知。

My question is -- how can a client protect itself from a faulting proxy? 我的问题是-客户端如何保护自己免受故障代理的侵害? shouldn't the proxy inform the client that it's not usable instead of letting the client try and use it? 代理不应该通知客户端它不可用,而不是让客户端尝试使用它吗?

The "problem" is that the method is oneway. “问题”是该方法是单向的。 At some degree, this is a fire and forget (put sessions aside) operation and if it throws an exception- the client has no way of knowing that. 从某种程度上说,这是一劳永逸的操作(如果搁置会话),并且如果引发异常,客户端将无法得知。 From the clients perspective, the request is successful as soon as it is received on the other side ( received not processed ). 从客户端的角度来看,请求是成功的,因为一旦被在另一侧接收( 接收处理 )。

I advise you to try the same with non one way first. 我建议您先尝试一种非单一方法。

Also, please post the code that you used to subscribe to the faulted event. 另外,请发布您用于订阅故障事件的代码。 What hosting are you using? 您正在使用什么托管? how are you creating the proxy? 您如何创建代理? (ChannelFactory?) (ChannelFactory?)

You can try to subscribe on the Faulted event of the ServiceHost (if you have one) and see whether this fires. 您可以尝试订阅ServiceHost的Faulted事件(如果有的话),然后查看是否触发。

Also, did you try querying the proxy for its state? 另外,您是否尝试查询代理的状态?

Also, please refer to this question on SO, I believe you may get your answer there. 另外,请参阅SO上的此问题 ,我相信您可以在那里得到答案。

Cheers 干杯

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

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