Frage

I've got a .NET client and server that works using NetTcpBinding on Windows, with the Microsoft .NET Framework.

I want to allow running the server on Linux, using Mono 3.2.7. However, when the Microsoft .NET client tries to call a method on the Mono server, it get this error message:

Unable to contact agent 192.168.0.xx: Error in deserializing body of reply message for operation 'MyMethod'. The empty namespace requires a null or empty prefix.

The empty namespace requires a null or empty prefix.

I've hunted around but can't get any clues as to how to fix this.

* Update *

I just tried it with BasicHttpBinding instead, and again it works fine with the Microsoft .NET Framework - but it still won't work with Mono. I get a similar error to the one I get with NetTcpBinding:

Cannot redefine the namespace for prefix '' used at current element

The server gives this stack trace:

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 

It's obviously something related to serialisation, but more than that I don't know.

I've fired up Wireshark to see what the data looks like on the wire, and the HTTP POST sent to the Windows server and the Mono server look exactly the same.

War es hilfreich?

Lösung

There were 2 parts to getting this working (annoyingly, both of which are required only by Mono - not by Microsoft .NET):

  1. Set IsReference to true on the DataContract attribute on classes you will send on the wire: [DataContract(IsReference = true)]

  2. Do not set a namespace on the DataContract attribute on those classes

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top