简体   繁体   English

WCF和Monotouch中的FaultExceptions无法序列化

[英]FaultExceptions in WCF and Monotouch are failing to serialize

I have a WCF service which I added to my Monotouch project using the instructions here . 我有一个WCF服务,已使用此处的说明将其添加到我的Monotouch项目中。 The Service works, but when it throws a FaultException, the client bombs with an error: 该服务可以工作,但是当它抛出FaultException时,客户端会炸弹并显示错误:

Expected element 'ExceptionDetail' in namespace 'http://schemas.datacontract.org/2004/07/System.ServiceModel', but found Element node 'MyTypeException' in namespace ... 在名称空间'http://schemas.datacontract.org/2004/07/System.ServiceModel'中需要元素'ExceptionDetail',但是在名称空间中找到了元素节点'MyTypeException'...

I'm setting up the client programmatically 我正在以编程方式设置客户端

BasicHttpBinding binding = new BasicHttpBinding();
binding.Name = "BasicHttpBinding_IService";
binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
binding.Security.Mode = BasicHttpSecurityMode.None;
EndpointAddress address = new EndpointAddress("http://myaddress.com/MyService.svc");
LoyaltyClient client = new LoyaltyClient(binding, address);

Any ideas? 有任何想法吗?

This is a bug in MonoTouch (which has been filed several times ). 这是MonoTouch中的一个错误(已提交 了好 几次 )。

The bug has been fixed, and the fix will most likely be included in the next version after 5.2 (though you might be able to get a hotfix if you contact support). 该错误已得到修复,并且该修复很可能将包含在5.2之后的下一版本中(尽管如果您与支持人员联系,则可能会获得修补程序)。


Update: November 13, 2014 更新:2014年11月13日

For users hitting this issue in more recent versions (after Xamarin.iOS 7 for example), note that the Mono WCF implementation requires the [FaultContract] when deserializing FaultException<T> instances that use custom types T for the exception details. 对于在较新版本(例如,在Xamarin.iOS 7之后)中遇到此问题的用户,请注意,在反序列化使用自定义类型T作为异常详细信息的FaultException<T>实例时,Mono WCF实现需要 [FaultContract]

For example, you'll need to add the [FaultContract] attribute to the method that throws the FaultException in the server-side service contract: 例如,您需要将[FaultContract]属性添加到在服务器端服务合同中引发FaultException的方法中:

[OperationContract]
[FaultContract(typeof(ContentFaultType))]
void MyMethodThatThrowsAFaultException();

After deploying this server-side change change you'll need to re-generate the client-side Silverlight proxy using SlSvcUtil. 部署此服务器端更改更改后,您将需要使用SlSvcUtil重新生成客户端Silverlight代理。

Looks like you did not declare the fault class using the FaultContractAttribute. 好像您没有使用FaultContractAttribute声明故障类。 When you don't do this the schema of the fault class does not go into the WSDL so the client does not know of it. 如果您不这样做,则故障类的架构不会进入WSDL,因此客户端不会知道它。

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

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