WCF 故障未正确传播到客户端
我们有以下 WCF 服务契约:
[ServiceContract(Namespace = "http://example.com", Name = "Service1")]
public interface IService1
{
[OperationContract]
[FaultContract(typeof(Fault1))]
ValidateUserResult ValidateUser(
string username,
string password);
}
[ServiceContract(Namespace = "http://example.com", Name = "Service1")]
public interface IService1Async
{
[OperationContract(AsyncPattern = true)]
[FaultContract(typeof(Fault1))]
IAsyncResult BeginValidateUser(
string username,
string password,
AsyncCallback callback,
object userState);
ValidateUserResult EndValidateUser(IAsyncResult asyncResult);
}
[DataContract(Namespace = "http://example.com")]
public class Fault1
{
}
我们在客户端调用 ValidateUser 的异步版本,并在服务器上抛出 FaultException
,但客户端收到的只是基础数据故障异常
。
未收到合同规定的故障的原因可能是什么?
We've got the following WCF Service Contracts:
[ServiceContract(Namespace = "http://example.com", Name = "Service1")]
public interface IService1
{
[OperationContract]
[FaultContract(typeof(Fault1))]
ValidateUserResult ValidateUser(
string username,
string password);
}
[ServiceContract(Namespace = "http://example.com", Name = "Service1")]
public interface IService1Async
{
[OperationContract(AsyncPattern = true)]
[FaultContract(typeof(Fault1))]
IAsyncResult BeginValidateUser(
string username,
string password,
AsyncCallback callback,
object userState);
ValidateUserResult EndValidateUser(IAsyncResult asyncResult);
}
[DataContract(Namespace = "http://example.com")]
public class Fault1
{
}
We are calling the async version of ValidateUser in the client side and we are throwing a FaultException<Fault1>
on the server, but all the client receives is the base FaultException
.
What can be the reason the contractually-specified fault is not being received?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们现在找到了原因。我们使用 ProvideFault 方法从服务行为生成故障。我们使用类似于 IErrorHandler 中的示例的代码msdn 中的 .ProvideFault
唯一的区别是我们没有对
Message.CreateMessage
重载传递正确的操作。我们准确地复制了手动抛出错误时生成的内容,瞧。我为没有提供最后细节的借口:-)
We found now why. We are generating the fault from a Service Behaviour using the ProvideFault method. There we use code similar to the example at IErrorHandler.ProvideFault in msdn
The only difference was that we weren't passing the right action on the
Message.CreateMessage
overload. We copied exactly what gets generated in the case that we manually throw the fault and voila.My excuses for not giving that last detail :-)
您能向我们展示您的通话的 catch 语句吗?合同和一切对我来说看起来都很好......
你按什么顺序检查错误?在检查
FaultException
或CommunicationException
之前,您必须先检查FaultException
- 您可能有任何机会这个顺序不知何故混淆了?当您调用该方法的同步版本时它是否有效?
Can you show us the catch statements for your call? The contract and everything looks fine to me...
In which order do you check for faults?? You would have to check for
FaultException<Fault1>
before checking forFaultException
orCommunicationException
- any chance you might have that order mixed up somehow?Does it work when you call the sync version of the method?