【发布时间】:2014-03-18 17:22:16
【问题描述】:
我有一个 .NET 客户端和服务器,可以在 Windows 上使用 NetTcpBinding 和 Microsoft .NET Framework。
我想允许在 Linux 上运行服务器,使用 Mono 3.2.7。但是,当 Microsoft .NET 客户端尝试调用 Mono 服务器上的方法时,会收到以下错误消息:
无法联系代理 192.168.0.xx:反序列化主体时出错 操作“MyMethod”的回复消息。空的命名空间需要一个 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 上,您应该小心选择哪个框架。例如,Web API 比 WCF 更好地支持,NHibernate 比 EF 更好。这是由于开源性质,而不是对框架的偏见。如果 Mono 的人有足够的资源,他们应该能够让一切正常工作。
-
WCF 的存在时间比 Web API 长得多,所以我认为即使使用没有安全性的基本 HTTP 绑定它也可以工作 :( 我已经在 Windows 上使用 WCF,所以它不会添加 Web API 也不理想。另外,我需要自托管服务
标签: .net wcf mono datacontractserializer