1

Ok, i'm really lost on this one. I created a wcf service which i post xml to and the services does something with the data. Everything works just great except when i put the opening xml tag at the very top of my xml. the data comes through as null when i view everything in debug mode.

My C# code in the wcf is something like this:

public interface ITest
{
    [OperationContract]
    void DoWork();

    [OperationContract]
    [WebDispatchFormatter]
    [WebInvoke(UriTemplate = "MyTest", Method = "*")]
    void MyTest(PassedIn request);
}

[Serializable]
[DataContract(Namespace = "", Name = "")]
public class PassedIn
{
    public PassedIn() { }

    [DataMember]
    public string firstname {get; set;}
    [DataMember]
    public string lastname {get; set;}
    [DataMember]
    public string email {get; set;}
}

Here's the different xml posts:

<mypost>
    <firstname>test</firstname>
    <lastname>foo</lastname>
    <email>test@bar.com</email>
</mypost>
<?xml version="1.0"?>
<mypost>
    <firstname>test</firstname>
    <lastname>foo</lastname>
    <email>test@bar.com</email>
</mypost>

I was able to fix this where data isn't lost when the tag is in the xml by adding the order to the datamember like so:

public class PassedIn
{
    public PassedIn() { }

    [DataMember (order=1)]
    public string firstname {get; set;}
    [DataMember  (order=2)]
    public string lastname {get; set;}
    [DataMember  (order=3)]
    public string email {get; set;}
}  

BUT now it has a reverse effect. If i don't have the "?xml version" tag the data comes through as null.

Has anyone run into this? Could really use some advice. Thanks

Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
user1096865
  • 245
  • 1
  • 4
  • 14

1 Answers1

1

i figured it out..when using the DataContractSerializer, order matters, but if you don't specify the order, by default the order is alphabetical which is why some data was getting set and others not.

I really didn't want order to matter, so i had to switch from DataContractSerializer to another serlization engine. XmlSerializer.

Links to some info that helped me: WCF Disable Deserialization Order Sensitivity http://msdn.microsoft.com/en-us/library/ms732038.aspx

Community
  • 1
  • 1
user1096865
  • 245
  • 1
  • 4
  • 14