Monday 13 January 2020

Creating xml child omit parent node (PHP Soap client)

tl;dr:

This is a question regarding the difference in handling SOAP OUTPUT between C# and PHP. There are questions on SO with accepted answers, stating that if you omit [DATAMEMBER] the parent is not included. This is true for C#; NOT PHP. I have tried several combinations with no success.

Problem: I'm working on a C# Soap web service with a few public methods. One takes and delivers XML accordingly to this World standard we are implementing.

C# output (note the missing parent group on orderlines):

<root>
  <node>Blublu</node>
  <Orderline>
      <data />
  </Orderline>
  <Orderline>
      <data />
  </Orderline>
  <node2>blabla<node2 />
</root>

PHP output (note the double orderline output):

<root>
  <node>Blublu</node>
  <OrderLine>
    <Orderline>
        <data />
    </Orderline>
    <Orderline>
        <data />
    </Orderline>
  </Orderline>
  <node2>blabla<node2 />
</root>

NP. Never mind if you think the example is invalid XML :)

I'm serializing a data class such as this:

class Output
{
    [XmlElement("OrderLine")]        
    [DataMember]    // ---<<<<<<<
    public List<OrderLine> OrderLine { get; set; }
}

Class Orderline has no specifications as such, except being public.

If I omit [DATAMEMBER] as property, the entire node disappears including all the children.

Now; On serialization to XML C# and PHP are not in agreement on how to read [DATAMEMBER]. This works fine in C#, but my client is using PHP (Yeah I know) and his response has the node as a parent too.

EDIT: Signature description in SOAP service (SERVICE.SVC):

public Output PlaceOrder(string userToken, order ediOrder)

I'm currently fiddling around with MessageContract on the class, MessageBodyMember on the property and xmlelement in places where the syntax is ok with it. Also; all sorts of combinations of these tags :)



from Creating xml child omit parent node (PHP Soap client)

No comments:

Post a Comment