WinPhone WCF:ErrorObject 解析/EndInvoke() 错误

发布于 2024-11-09 08:15:05 字数 3772 浏览 0 评论 0原文

我正在编写一个 WindowsPhone 应用程序,该应用程序在 WCF 的帮助下使用基于 SOAP 的 WebService。 我遇到了问题,解析的某些内容无法正常工作。有生成的类(Reference.cs),由 Visual Studio 根据服务的 wsdl 描述生成。如果我调用服务方法并且没有错误,那么一切都很好,请求已发送并且我得到了答复。但如果出现问题,则会发送请求并且服务器返回一个错误对象。该对象名为“ClientException”并由 wsdl 文件指定。现在的问题是代码无法获取(错误)返回值并且无法返回异常。具体的 base.EndInvoke() 失败。这似乎是一个 winphone/silverlight 问题,用普通的 wcf 客户端进行测试,服务和/或解析没有问题。

下面是一些代码来说明我的意思:

Reference.cs

        public IAsyncResult BegingetCubeState(AsyncCallback callback, object asyncState)
        {
            object[] _args = new object[0];
            IAsyncResult _result = base.BeginInvoke("getCubeState", _args, callback, asyncState);
            return _result;
        }

        public CubeState EndgetCubeState(IAsyncResult result)
        {
            object[] _args = new object[0];
            Debugger.Break();
            CubeState _result = ((CubeState)(base.EndInvoke("getCubeState", _args, result)));
            return _result;
        }

base.EndInvoke("getMaxCubeState", _args, result) 中的代码失败,

InvalidCastException
bei System.ServiceModel.Dispatcher.XmlSerializerObjectSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
bei System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlReader reader, Boolean verifyObjectName)
bei System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName)
bei System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
bei System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
bei System.ServiceModel.Dispatcher.XmlSerializerFaultFormatter.CreateFaultException(MessageFault messageFault, String action)
bei System.ServiceModel.Dispatcher.FaultFormatter.Deserialize(MessageFault messageFault, String action)
bei System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
bei System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
bei System.ServiceModel.ClientBase1.ChannelBase1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
bei WindowsPhoneStr.ServiceReferenceSoap.RemoteClient.RemoteClientChannel.EndgetCubeState(IAsyncResult result)
bei WindowsPhoneStr.ServiceReferenceSoap.RemoteClient.WindowsPhoneStr.ServiceReferenceSoap.IRemote.EndgetCubeState(IAsyncResult result)
bei WindowsPhoneStr.ServiceReferenceSoap.RemoteClient.OnEndgetCubeState(IAsyncResult result)
bei System.ServiceModel.ClientBase1.OnAsyncCallCompleted(IAsyncResult result)
bei System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
bei System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously, Exception exception)
bei System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.CallComplete(Boolean completedSynchronously, Exception exception)
bei System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishSend(IAsyncResult result, Boolean completedSynchronously)
bei System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.SendCallback(IAsyncResult result)
bei System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
bei System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously, Exception exception)
bei System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult result)
bei System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2)
bei System.Threading.ThreadPool.WorkItem.doWork(Object o)
bei System.Threading.Timer.ring()

我希望我足够详细地解释了问题。有办法解决这个问题吗?

感谢您抽出时间!

I'm programming a WindowsPhone App which is using a SOAP based WebService, with help of WCF.
I've got the problem, that something with the parsing doesn't work like it should work. There is the generated class (Reference.cs), generated by visual studio on the basis of the wsdl description of the service. If I call a servicemethod and there is no error all is fine, request is send and I get an answere. But if something goes wrong, request is sent and server returns an error object. This object is named "ClientException" and specified by the wsdl file. The problem is now that the Code fails get the (error) return value and can not return the exception. Concrete base.EndInvoke() fails. This seems to be a winphone / silverlight problem, tested with a normal wcf client there are no problems with the service and/or parsing.

Here is some code to show what I mean:

Code from Reference.cs

        public IAsyncResult BegingetCubeState(AsyncCallback callback, object asyncState)
        {
            object[] _args = new object[0];
            IAsyncResult _result = base.BeginInvoke("getCubeState", _args, callback, asyncState);
            return _result;
        }

        public CubeState EndgetCubeState(IAsyncResult result)
        {
            object[] _args = new object[0];
            Debugger.Break();
            CubeState _result = ((CubeState)(base.EndInvoke("getCubeState", _args, result)));
            return _result;
        }

base.EndInvoke("getMaxCubeState", _args, result) fails with

InvalidCastException
bei System.ServiceModel.Dispatcher.XmlSerializerObjectSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
bei System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlReader reader, Boolean verifyObjectName)
bei System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName)
bei System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
bei System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
bei System.ServiceModel.Dispatcher.XmlSerializerFaultFormatter.CreateFaultException(MessageFault messageFault, String action)
bei System.ServiceModel.Dispatcher.FaultFormatter.Deserialize(MessageFault messageFault, String action)
bei System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
bei System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
bei System.ServiceModel.ClientBase1.ChannelBase1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
bei WindowsPhoneStr.ServiceReferenceSoap.RemoteClient.RemoteClientChannel.EndgetCubeState(IAsyncResult result)
bei WindowsPhoneStr.ServiceReferenceSoap.RemoteClient.WindowsPhoneStr.ServiceReferenceSoap.IRemote.EndgetCubeState(IAsyncResult result)
bei WindowsPhoneStr.ServiceReferenceSoap.RemoteClient.OnEndgetCubeState(IAsyncResult result)
bei System.ServiceModel.ClientBase1.OnAsyncCallCompleted(IAsyncResult result)
bei System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
bei System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously, Exception exception)
bei System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.CallComplete(Boolean completedSynchronously, Exception exception)
bei System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishSend(IAsyncResult result, Boolean completedSynchronously)
bei System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.SendCallback(IAsyncResult result)
bei System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
bei System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously, Exception exception)
bei System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(IAsyncResult result)
bei System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2)
bei System.Threading.ThreadPool.WorkItem.doWork(Object o)
bei System.Threading.Timer.ring()

I hope I explained the problem detailed enought. Is there a solution to fix this problem?

Thanks for your time!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假扮的天使 2024-11-16 08:15:05

快速浏览一下错误消息就会发现这是客户端的强制转换异常,因此尝试在客户端反序列化该对象是不愉快的。

我无法看到 wsdl,但看起来您的服务器和客户端对象定义之间不匹配。可能您更改了服务器上返回消息的元素,但没有刷新客户端。这也可以解释为什么它在您的测试项目中起作用 - 您从它们中获取正确的服务参考数据,而您的实际项目具有旧的服务定义。

您是否尝试过在客户端刷新 WCF 服务信息? (右键单击客户端项目中的服务,然后单击“更新”)

A quick glance at the error message shows it's a cast exception on the client side, so it's unhappy trying to deserialize the object on the client end.

I'm unable to see the wsdl but it looks like there is a mismatch between your server and client object definitions. Possibly you changed elements of the return message on the server but didn't refresh the client. This would also explain why it works in your test projects - you're getting the correct service reference data from them while your actual project has an old service definition.

Have you tried refreshing your WCF service information on the clent? (right-click on the service in the client project and click "Update")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文