2010-10-04 41 views
0

我使用WCF服務來實現我的Web服務我有問題,當我嘗試調用我的函數,它將URL作爲輸入參數並返回一個已定義的對象類由我。數據合同的類字段是用戶定義的類本身

public class Service: IService<br> 
{ 
    public ClassWS My_Stores(String URL) 
    { 
     try 
     { 
      //ClassWS is a class which has other classes like address() defined by me 
      ClassWS My_WS = new ClassWS(); 
      return ClsStore.My_Stores(URL); 
     } 
     catch (Exception ex) 
     {} 
    } 
} 

[DataContract] 
public class ClassWS 
{ 
    [DataMember] 
    public granularity Granularity; 
    [DataMember] 
    public address[] Address = new address[5]; 
    [DataMember] 
    public Store[] Stores; 
    [DataMember] 
    public int Status; 

    public ClassWS My_Stores(String URL) 
    { 
     ClassQuery q = new ClassQuery(); 
     return (sq.PopulateStores(URL)); 
    } 
} 

我已經在DataContract中包含了我定義的每個類,就像我在上面的類中所做的一樣。當我試圖返回ClassWS,但沒有任何與返回Store []或地址[]

錯誤時,我收到以下錯誤提示。錯誤不會在服務代碼中返回,但會在將值重新設置爲代理時發生。

底層連接已關閉: 連接意外地關閉了 。服務器堆棧跟蹤:
在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(引發WebException 引發WebException,HttpWebRequest的請求, HttpAbortReason abortReason)在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(時間跨度 超時)在 System.ServiceModel.Channels.RequestChannel.Request(消息 消息,時間跨度超時)處 System.ServiceModel.Channels.ServiceChannel.Call System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息 消息,時間跨度超時)(字符串 動作,布爾oneway, ProxyOperationRuntime操作, 對象[]項,在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 包括MethodCall,ProxyOperationRuntime 操作)在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke對象[]奏,時間跨度 超時) (即時聊天 消息)[0]時異常重新拋出:
在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即時聊天 reqMsg,即時聊天retMsg)在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData & msgData,Int32類型)在 IFindStore.My_Stores(String URL) FindStoreClient.My_Stores(String URL) 內部異常:底層 連接已關閉:連接 已意外關閉。在 System.Net.HttpWebRequest.GetResponse() 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(時間跨度 超時)

我想知道如何獲得一個datacontract了班級有其他班級作爲其領域。

我應該使用datacontractserialzer將對象寫入流中(即使數據協定使用datacontractserializer)。我應該使用XmlSerializer嗎?

在此先感謝

回答

2

在一般情況下,只要你有DataContract +數據成員的所有相關類,你似乎已經具備,那就是所有需要爲DataContractSerializer的序列化他們。

以下

The underlying connection was closed: The connection was closed unexpectedly. 
Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities. 
ProcessGetResponseWebException (WebException ..... 

是一個通用的例外,你通常會看到如果在您的服務未處理的異常,這是造成被關閉遠程連接。

它不一定是與你的類的序列。

我建議你一步到您的服務方法,同時調試因爲這將確切地告訴你什麼異常被拋出,爲什麼!

+0

服務沒有引起它返回正確答案的任何錯誤。錯誤發生在方法的最後一個「}」之後。我認爲當它將返回值綁定到代理時,它會違反合同。即使我只返回新ClassWS,公共ClassWS My_Stores(字符串URL)出現的錯誤 { 嘗試 { 返回新ClassWS(); } catch(Exception ex) {} } – vasanth 2010-10-04 13:15:50

+0

@vasanth - 假設您的服務用於工作,您的服務合約最近可能已更改,但客戶端代理未更新?也許你可以嘗試通過執行「更新服務參考」來刷新您的服務參考,以確保?這種錯誤在這種情況下是非常可能的?這也應該可以通過進入代理類進行調試? – InSane 2010-10-04 13:34:24

+0

@InSane錯誤盛行,甚至當我更新服務的參考,我試圖WCF測試客戶端在VS2010,它具有相同的錯誤,當我嘗試調用WCF中測試客戶端服務。 – vasanth 2010-10-04 13:55:31

相關問題