我在WCF的帮助下编写了一个使用基于SOAP的WebService的WindowsPhone应用程序。 我遇到了问题,解析的东西不能正常工作。生成的类(Reference.cs)由visual studio根据服务的wsdl描述生成。如果我调用servicemethod并且没有错误一切都很好,请求发送,我得到回复。但是如果出现问题,则发送请求并且服务器返回错误对象。此对象名为“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()
我希望我解释了详细的问题。有解决方案可以解决这个问题吗?
谢谢你的时间!
答案 0 :(得分:0)
快速浏览一下错误消息,显示它是客户端的强制转换异常,因此尝试反序列化客户端上的对象并不高兴。
我无法看到wsdl,但看起来服务器和客户端对象定义之间存在不匹配。可能您在服务器上更改了返回消息的元素,但没有刷新客户端。这也可以解释为什么它适用于您的测试项目 - 当您的实际项目具有旧的服务定义时,您将从中获取正确的服务引用数据。
您是否尝试过刷新您的WCF服务信息? (右键单击客户端项目中的服务,然后单击“更新”)