tags:

views:

405

answers:

1

Hi all:

I am writing a native C/C++ .dll program which calls to .dll functions of many third party C/C++ libraries and returns a c/c++ structure array (SA) of 18 columns by 0-n lines. This returned value is then captured by a WCF C# web service program which "interop" with my .dll and, using .net xml library, serialize the result before sending the message to the web service client.

I can see an overhead here: (a) prepare data in C/C++ to populate the SA before returning and, (b) serialize that SA into XML once it is received by the C# web service program.

To avoid this overhead I think that instead of populating the SA in my C/C++ dll, I should populate into a XML-serialized string or file, then return this result to the C# web service program which will only send the already serialized data directly to the client.

At this point I would like to know:

1) If my thought is correct.

2) If yes, apart from populating data into XML I would also like to include -as a header- the name of the columns, lenghts and datatypes. Somebody said me that I should create an XSD string/file for describing that header. What do you think about this?

3) What kind of things should I consider into the C# program for not having problems with the returning XML data? XSD data?

Thanks for your courtesy in reading this.

A: 

XSD (XML Schema) is mostly useful for validating and describing XML formats. It's not something you usually pass around in my experience, often the endpoints already have the Schema at hand. If you have control over both applications, which I assume you do, you could omit that and just go with the XML.

You could however have the Schema in your C# code and validate the XML from the C++ portion, if you for some reason don't trust it. Also if you are gonna hand this XML to some third party a schema can also be useful.

One thing you could have a problem with is the character encoding. You need to make sure that your XML is utf-8 (or something else if you've set the encoding attribute in the XML-declaration accordingly, but utf-8 is default) when you pass it to the client. This could be done in the C++ portion, or probably easier in the C# portion.

I think you are correct that there is an unnecessary step, but perhaps it's useful to consider if you might want to use the data from the C++ portion in some other form that is not XML. It might be that the format you already have is useful in those circumstances.


I included an example schema for you, each row has a name, length and type:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="row-column-format">
  <xs:element name="rows">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="column">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute name="name" type="xs:string" />
                <xs:attribute name="type" type="xs:string" />
                <xs:attribute name="length" type="xs:int" />
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

It describes an XML format of this structure:

<?xml version="1.0" encoding="utf-8"?>
<rows xmlns="row-column-format">
  <column name="name1" type="type1" length="1" xmlns="">column1</column>
</rows>
Skurmedel