0

Trying to create a cxml request from a c# class auto generated from the official cxml specification(http://cxml.org/) through xsd. I can serialize the header, and I can serialize the setupRequest, but I keep getting errors when trying to serialize the whole cxml. I wonder if anyone knows how to implement the classes from the cxml specification correctly. Since the auto generated class is 38401 lines I didn't include it here, and I'm not really sure how to share it.

var cxml = new cXML();
var header = new Header();
var requestWrapper = new Request();
var setupRequest = new PunchOutSetupRequest();
requestWrapper.Item = setupRequest;
cxml.Items = new object[] { header, setupRequest };

-- skipped the data implementation since i have successfully serialized setupRequest and header ---

  var sw = new StringWriter();
  using (var writer = XmlWriter.Create(sw, xmlSettings))
  {
     XmlSerializer serializer = new XmlSerializer(cxml.GetType());
     serializer.Serialize(writer, cxml);
     return await Task.FromResult(sw.ToString());
  }

I cannot seem to serialize the requestWrapper with the setupRequest inside it either.

  • XML serialization requires classes to be hard coded and the root class has to be in the code :new XmlSerializer(typeof("root class")); – jdweng Jun 22 '21 at 10:35
  • So I will have to create a class that covers my use case that implements the root class? @jdweng – Hallisloak Jun 22 '21 at 11:06
  • Yes. If you have a schema (xsd) there are tools to automatically generate c# classes. Otherwiase yo uhave to manually generate the classes. – jdweng Jun 22 '21 at 11:40
  • Used the Microsoft xsd tool with /classes /language:CS parameters. The cXML class and the other classes are from the xsd. So should I not be able to use them like that? – Hallisloak Jun 22 '21 at 12:00
  • The requestWrapper is the message you are sending. The cxml can either be the body of the request or you can make the cxml a MIME attachment. In either case the serialize string is the content of the request. – jdweng Jun 22 '21 at 12:16
  • The final request should be in this format: https://punchoutcommerce.com/guides/punchout/cxml-punchout-setup-request/#_example_punchoutsetuprequest So i need the header data and the cxml tags to be in the final xml too. – Hallisloak Jun 22 '21 at 12:22

0 Answers0