我已經創建了一個WCF Web服務,該服務使用Jabber.net連接到XMPP服務。這個想法是,該服務將充當Silverlight客戶端用於消息傳遞的代理。雙工通信並傳遞異常
IMessagingClient.cs:
[OperationContract(IsOneWay = true, AsyncPattern = true)]
IAsyncResult BeginError(Exception ex, AsyncCallback callback, object state);
void EndError(IAsyncResult result);
在我的服務器代碼,但是,當一個SocketException發生時未能通過例外,我已經連接的錯誤處理程序的JabberClient
private void xmppClient_OnError(object sender, Exception ex)
{
lock (xmppClient)
{
Debug.WriteLine("xmppClient_OnError: {0}", ex);
// Let the client know there has been a problem
client.BeginError(ex, OnSendErrorCompleted, client);
}
}
。
System.ServiceModel.CommunicationException: There was an error while trying to serialize parameter http://tempuri.org/:ex . The InnerException message was 'Type 'bedrock.net.AsyncSocketConnectionException' with data contract name 'AsyncSocketConnectionException:http://schemas.datacontract.org/2004/07/bedrock.net' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
現在我明白,它不能被序列化,因爲它不知道如何發送例外,我不相信我本來也應該發送此特定的異常,因爲它然後使客戶需求瞭解服務器上消息傳遞的內部工作原理。
但是,這樣做的最好方法是什麼?我是否應該將這種異常從服務器發送到客戶端?我看到一些使用`FaultContract'的例子,但不知道如何(或它應該)應用於推送。
這一切聽起來很明智。我只是不完全清楚你是如何通過這裏使用的推送機制發送故障的。 – Firedragon
我已經離開了一下。 – DerekGn
@Firedragon現在我不能編輯上面的代碼:<你遇到的問題是隻能在操作契約屬性上指定錯誤契約,在上面的例子中,該契約屬性允許client.BeginError(...)發送錯誤如果在處理BeginError處理過程中發生錯誤,則返回服務器。
我的解釋是將錯誤契約類型添加到BeginError的定義中(例如,定義一個Fault契約類並在回調中傳遞它,這將解決序列化問題。 – DerekGn