Silverlight呼叫WebService出現CommunicationException The remote server returned an error: NotFound的一種可能原因
阿新 • • 發佈:2019-01-31
僅作為個人記錄:
今天研究了一下WCF Duplex雙工通道在SilverLight中進行通訊的問題,在網上找到了兩篇MSDN的關於用這兩者來實現一個線上聊天程式 (service: http://msdn.microsoft.com/zh-cn/library/cc645027(VS.95).aspx and client: http://msdn.microsoft.com/zh-cn/library/cc645028(VS.95).aspx)。按照這裡給出的程式碼,編譯測試後老是出現文章標題中出現的問題,查了很多資料,但大部分都是提到通過更改web.config改變允許傳輸的位元組的多少,這些方法都不能解決這個問題。後來將
this.AddServiceEndpoint( typeof(IDuplexService), new CustomBinding( pdbe, new TextMessageEncodingBindingElement( MessageVersion.Soap11, System.Text.Encoding.UTF8), new HttpTransportBindingElement()), "");
改為
this.AddServiceEndpoint( typeof(IDuplexService), new CustomBinding( pdbe, new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement()), "");
然後將
Message returnMessage =
Message.CreateMessage(MessageVersion.Soap11, "Silverlight/IDuplexService/Receive", text);
改為:
Message returnMessage =
Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "Silverlight/IDuplexService/Receive", text);
這個問題就解決了,奇怪的是msdn裡還專門提到了Silverlight僅支援Soap11的,但現在改為Soap12WSAddressing10不但解決了這個問題,
而且用起來一切正常,還沒弄清楚原因