我有一个.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看起来完全一样。
答案 0 :(得分:0)
有两个部分让这个工作(令人讨厌的是,这两个部分都是仅由Mono - 而不是Microsoft .NET):
在您将在线路上发送的类的DataContract
属性上将IsReference设置为true:
[DataContract(IsReference = true)]
不在这些类的DataContract
属性上设置命名空间