[英]WCF - Mono server with Microsoft .NET client
我有一個.NET客戶端和服務器,可以在Windows上使用NetTcpBinding
和Microsoft .NET Framework來工作。
我想允許使用Mono 3.2.7在Linux上運行服務器。 但是,當Microsoft .NET客戶端嘗試在Mono服務器上調用方法時,它會收到以下錯誤消息:
無法聯系代理192.168.0.xx:反序列化“ MyMethod”操作的回復消息正文時出錯。 空的名稱空間要求使用null或空前綴。
空的名稱空間要求使用null或空前綴。
我已經四處搜尋,但是沒有任何有關如何解決此問題的線索。
*更新*
我只是用BasicHttpBinding
嘗試了一下,然后再次在Microsoft .NET Framework上正常工作-但仍然不能與Mono一起工作。 我得到的錯誤與NetTcpBinding
得到的錯誤類似:
無法為當前元素使用的前綴''重新定義名稱空間
服務器給出以下堆棧跟蹤:
Exception Cannot redefine the namespace for prefix '' used at current element at System.Xml.XmlTextWriter.WriteEndAttribute () [0x0028e] in /home/user/mono/mono/mcs/class/System.XML/System.Xml/XmlTextWriter2.cs:995
at System.Xml.DefaultXmlWriter.WriteEndAttribute () [0x00000] in /home/user/mono/mono/mcs/class/System.XML/System.Xml/DefaultXmlWriter.cs:116
at System.Xml.XmlSimpleDictionaryWriter.WriteEndAttribute () [0x00000] in /home/user/mono/mono/mcs/class/System.Runtime.Serialization/System.Xml/XmlSimpleDictionaryWriter.cs:97
at System.Xml.XmlWriter.WriteAttributeString (System.String prefix, System.String localName, System.String ns, System.String value) [0x00025] in /home/user/mono/mono/mcs/class/System.XML/System.Xml/XmlWriter.cs:270
at System.Xml.XmlWriter.WriteAttributeString (System.String localName, System.String value) [0x00000] in /home/user/mono/mono/mcs/class/System.XML/System.Xml/XmlWriter.cs:254
at System.Xml.XmlDictionaryWriter.WriteXmlnsAttribute (System.String prefix, System.String namespaceUri) [0x00077] in /home/user/mono/mono/mcs/class/System.Runtime.Serialization/System.Xml/XmlDictionaryWriter.cs:396
at System.Runtime.Serialization.DataContractSerializer.WriteStartObject (System.Xml.XmlDictionaryWriter writer, System.Object graph) [0x0022f] in /home/user/mono/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:501
at System.Runtime.Serialization.XmlObjectSerializer.WriteObject (System.Xml.XmlDictionaryWriter writer, System.Object graph) [0x00000] in /home/user/mono/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlObjectSerializer.cs:113
at System.ServiceModel.Dispatcher.DataContractMessagesFormatter+DataContractBodyWriter.WriteMessagePart (System.Xml.XmlDictionaryWriter writer, System.ServiceModel.Description.MessageBodyDescription desc, System.ServiceModel.Description.MessagePartDescription partDesc, System.Object obj) [0x00049] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:503
at System.ServiceModel.Dispatcher.DataContractMessagesFormatter+DataContractBodyWriter.OnWriteBodyContents (System.Xml.XmlDictionaryWriter writer) [0x00054] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs:486
at System.ServiceModel.Channels.BodyWriter.WriteBodyContents (System.Xml.XmlDictionaryWriter writer) [0x00000] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/BodyWriter.cs:57
at System.ServiceModel.Channels.SimpleMessage.OnWriteBodyContents (System.Xml.XmlDictionaryWriter writer) [0x00000] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/MessageImpl.cs:331
at System.ServiceModel.Channels.Message.WriteBodyContents (System.Xml.XmlDictionaryWriter writer) [0x00022] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:183
at System.ServiceModel.Channels.Message.WriteBody (System.Xml.XmlDictionaryWriter writer) [0x0001c] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:168
at System.ServiceModel.Channels.Message.OnWriteMessage (System.Xml.XmlDictionaryWriter writer) [0x00065] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:293
at System.ServiceModel.Channels.Message.WriteMessage (System.Xml.XmlDictionaryWriter writer) [0x00026] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:195
at System.ServiceModel.Channels.TextMessageEncoder.WriteMessage (System.ServiceModel.Channels.Message message, System.IO.Stream stream) [0x0004a] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/TextMessageEncoder.cs:122
at System.ServiceModel.Channels.Http.HttpRequestContext.InternalReply (System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00034] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpRequestContext.cs:139
at System.ServiceModel.Channels.Http.HttpRequestContext.Reply (System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpRequestContext.cs:101
at System.ServiceModel.Dispatcher.MessageProcessingContext.Reply (Boolean useTimeout) [0x00026] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/MessageProcessingContext.cs:96
at System.ServiceModel.Dispatcher.OperationInvokerHandler.Reply (System.ServiceModel.Dispatcher.MessageProcessingContext mrc, Boolean useTimeout) [0x0001d] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/OperationInvokerHandler.cs:69
at System.ServiceModel.Dispatcher.OperationInvokerHandler.ProcessRequest (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00044] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/OperationInvokerHandler.cs:29
at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseRequestProcessorHandler.cs:15
at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00017] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseRequestProcessorHandler.cs:16
at System.ServiceModel.Dispatcher.HandlersChain.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x0000b] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseRequestProcessor.cs:72
at System.ServiceModel.Dispatcher.BaseRequestProcessor.ProcessRequest (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00018] in /home/user/mono/mono/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseRequestProcessor.cs:26
顯然,這與序列化有關,但不止於此。
我啟動了Wireshark,以查看數據在網絡上的樣子,並且發送到Windows服務器和Mono服務器的HTTP POST看起來完全一樣。
要使此工作正常運行,有兩個部分(令人討厭的是,這兩個部分僅在Mono中才需要,而在Microsoft .NET中則不需要):
在將在線發送的類的DataContract
屬性上,將IsReference設置為true: [DataContract(IsReference = true)]
不要設置一個命名空間的DataContract
在這些類屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.