Generating C# Classes from WebEx Request XML

Posted on Updated on

Just recently I worked on a project that required me to consume some WebEx services, after the first look at some sample code I  decided not to go the route of building XML strings whenever there was a need to communicate with the WebEx servers. I wanted the ability to serialize and deserialize xml requests and responses, so here is what I did to accomplish this in C# and xsd.exe.

Sample WebEx xml request: Authenticate user

<?xml version="1.0" encoding="ISO-8859-1"?>
<serv:message xmlns:xsi=""
        <bodyContent xsi:type="java:com.webex.service.binding.user.AuthenticateUser">
                message will go here
  1. Copy the XML string to notepad and save as helper.xml
  2. At the developer command prompt type cd\ then press Enter\Return
  3. Type the path to helper.xml then press Enter\Return
  4. At the command prompt type xsd helper.xml then press Enter\Return [This will generate the helper.xsd file]
  5. Next type xsd helper.xsd /c /f then press Enter\Return  [Will generate C# classes based on the helper.xsd file]

Now lets see how we can manually load these generated classes then serialize them to XML for posting to the WebEx REST API Servers.

private void TestSerialization()
 var msgSecurityContext = new messageHeaderSecurityContext()
 email = "",
 partnerID = "webexpartner",
 password = "pass",
 siteName = "ian0830",
 webExID = "siteadmin"

var msgBodyContent = new messageBodyBodyContent() { samlResponse = "samlResponse message will go here" };

var header = new messageHeader() { securityContext = new messageHeaderSecurityContext[] { msgSecurityContext } };
var body = new messageBody() { bodyContent = new messageBodyBodyContent[] { msgBodyContent } };

var msg = new message() { Items = new object[] { header, body } };

var xmlns = new System.Xml.Serialization.XmlSerializerNamespaces();

xmlns.Add("serv", "");
xmlns.Add("xsi", "");

System.Xml.Serialization.XmlSerializer searializer = new System.Xml.Serialization.XmlSerializer(msg.GetType());

searializer.Serialize(Console.Out, msg, xmlns);

This produces an identical XML string as the one shown above.

5 thoughts on “Generating C# Classes from WebEx Request XML

    Ry said:
    November 15, 2013 at 6:54 pm

    hi quick question:
    How do you get xsi:type=”java:com.webex.service.binding.user.AuthenticateUser” in your output xml?

    Romaine Carter responded:
    November 15, 2013 at 7:22 pm

    The xml was a sample from the WebEx docs.

    Ry said:
    November 18, 2013 at 12:35 pm

    Thank you for your answer. I am trying to achieve to access XML-API of WebEx. I have hard time related to action method passing with the bodycontent. In you example case when I create the xml after serialization (this xml created using xsd ) what I get is :


    samlResponse message will go here

    as you see there is no property in hte bodyContent tag. When I send this XML to the WebEx testing servers, I get the following failure message:

    Failed to get SiteUrl

    Am I missing something in the procedure?


      Ry said:
      November 18, 2013 at 12:46 pm

      all xml comments lost after submit. ::(

        Josh said:
        June 1, 2015 at 3:52 pm

        I take it you never got a response to this question? Having the same problem.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s