2011-05-23 27 views
3

我編程的WindowsPhone應用程序正在使用基於SOAP的WebService,在WCF的幫助下。 我有這個問題,解析的東西不能像它應該工作。生成的類(Reference.cs)由Visual Studio根據服務的wsdl描述生成。如果我打電話給servicemethod並且沒有錯誤,一切正常,請求發送並且我得到一個回答。但是如果出現問題,則發送請求並且服務器返回一個錯誤對象。該對象被命名爲「ClientException」並由wsdl文件指定。現在的問題是,代碼無法獲得(錯誤)返回值,並且無法返回異常。具體base.EndInvoke()失敗。這似乎是一個winphone/silverlight問題,用普通的wcf客戶端進行測試,服務和/或解析沒有問題。WinPhone WCF:ErrorObject解析/ EndInvoke()錯誤

下面是一些代碼來說明我的意思:從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,結果)失敗,

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

您可以發佈WSDL嗎?也許SL有一種類型不理解? – 2011-08-18 15:21:29

+0

wsdl:http://pastebin.com/qRJPs3n1 wsdl界面:http://pastebin.com/2G2bJCsW – 2011-09-02 07:49:24

回答

0

快速瀏覽錯誤消息顯示它是客戶端上的強制異常,因此嘗試反序列化客戶端上的對象時不太高興。

我無法看到wsdl,但看起來您的服務器和客戶端對象定義之間存在不匹配。可能您更改了服務器上返回消息的元素,但未刷新客戶端。這也可以解釋爲什麼它可以在你的測試項目中工作 - 當你的實際項目有一箇舊的服務定義時,你從他們那裏獲得正確的服務參考數據。

您是否嘗試過在clent上刷新WCF服務信息? (右鍵單擊客戶端項目中的服務並單擊「更新」)

+0

我試圖刷新服務,但沒有解決問題。看來,WP7 Framewok無法傳遞錯誤對象(ClientException類型)。 我已經在前一篇文章中發佈了wsdl文件的鏈接。 – 2011-09-05 12:20:20