我正在创建一个可以使用WCF服务与Dynamics AX通信的移动应用程序。
我是Xamarin的新手,我试图为共享的IOS和Android应用程序创建一个PCL库。我也在开发一款Windows Phone App,现在几乎可以使用。我正在使用创建的WCF服务,该服务与Dynamics AX进行所有通信,并且该服务使用元数据公开其方法。我已经为Windows Phone解决方案添加了一个服务引用,生成的代理就像一个魅力,我应该说我正在使用SOAP。
但是,如果我将生成的Reference.cs文件传输到我的Xamarin PCL项目并调用我的方法,则会出现以下错误:
Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.Serialization.SerializationException: Expected element 'ExceptionDetail' in namespace 'http://schemas.datacontract.org/2004/07/System.ServiceModel', but found Element node 'AifFault' in namespace 'http://schemas.microsoft.com/dynamics/2008/01/documents/Fault'
at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Xml.XmlReader reader, System.Type declaredType, System.Runtime.Serialization.KnownTypeCollection knownTypes, IDataContractSurrogate surrogate, System.Runtime.Serialization.DataContractResolver resolver, System.Runtime.Serialization.DataContractResolver defaultResolver, System.String name, System.String ns, Boolean verifyObjectName) [0x0003e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlFormatterDeserializer.cs:63
at System.Runtime.Serialization.DataContractSerializer.ReadObject (System.Xml.XmlDictionaryReader reader, Boolean verifyObjectName) [0x00024] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:363
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) [0x00000] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlObjectSerializer.cs:76
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Description.OperationDescription od, System.Object[] parameters) [0x0019b] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:550
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x00038] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:496
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x0001c] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/7.4.0.108/src/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:477
--- End of inner exception stack trace ---
问题只发生在AX返回AIFFault异常时,由于某种原因它无法被Xamarin捕获..它在Windows Phone中的Visual Studio中捕获得很好。
以下是拨打电话的代码:
try{
var result = await _service.ExecuteGetMethod(MyRecord)
}
catch(FaultException fe){
ShowError(fe);
}
这很好用,并且来自AX的错误消息显示在fe.Message中,但在Xamarin中运行完全相同的错误会给我上述错误。
我是否需要在我的WCF服务中的某处添加AIFFault,以便客户能够看到它?