0

I imported a WSDL into my project for a 3rd party system. (The WSDL is a nightmare)

Anyway in order for my request to receive a valid response i have been told by the 3rd party i need to send through an empty object in one of the requests.

Lets assume a valid request looks like the below:

<Request>
  <UserID>123456</UserID>
  <ComplexObj/>
</Request>

If i send the above XML manually in SOAP UI then I get a valid response. However because I'm doing this in C# i have imported the WSDL into visual studio and have a service reference generated i cannot figure out a way for the request to generate the empty ComplexObj.

If i set ComplexObj to null in the code it is not included in the request. If i create a new instance of the ComplexObj then the request includes all the variables within the ComplexObj which is also invalid.

CathalMF
  • 9,705
  • 6
  • 70
  • 106
  • Did you try to apply `NonSerializedAttribute` to all the attributes of your ComplexObj ? If it doesn't work maybe you'll have to have to implement your own Custom Serialization methods for this class. More info here : https://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializable.aspx – Irwene May 13 '15 at 15:04

1 Answers1

1

HAve you tried to declare ComplexObjproperty to serialize even if it is null. For that you'll need to find the definition of class and add

[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]

for that property. That 'll include it into SOAP request as <ComplexObj xsi:nil="true" />

  • Im not manually generating the XML. It being generated in the background by the service reference created by the WSDL. – CathalMF May 13 '15 at 15:10
  • Helpful but still doesnt work fully. This adds nill="true" to the xml which causes the 3rd party to error. . Ive dropped an email to the 3rd party so see if they can fix their side to be less sensitive. – CathalMF May 13 '15 at 15:50
  • Actually, i've looked through couple of post here, and it looks like your 3rd party is trying to go against best practice. http://stackoverflow.com/questions/29118057/removing-nill-true-from-wcf-request – Valentyn Vynogradskiy May 14 '15 at 11:56
  • http://stackoverflow.com/questions/1969993/is-it-better-to-return-null-or-empty-collection – Valentyn Vynogradskiy May 14 '15 at 11:56
  • Oh ya they totally are. You should see some of the stuff they have me fudging. Cant wait to get this project out the door. lol – CathalMF May 14 '15 at 14:41