许多SOAP服务需要直接使用XML Schema的类型。gSOAP工具采用的默认编码方式是SOAP RPC编码,这种编码只需要能在多种情况下使用。尽管如此,使用XSD类型的消息还是需要提高互操作性。XSD类型在进行typedef后包含在头文件中,用作gSOAP soapcpp2工具的输入。经过typedef后的类型名保持与XML Schema类型(XSD 类型)一致。例如,以下的typedef声明定义了C/C++内置类型对应的XSD类型:
//Contents of header file
...
typedef char *xsd string; // encode xsd string value as the xsd:string schema type
typedef char *xsd anyURI; // encode xsd anyURI value as the xsd:anyURI schema type
typedef float xsd float; // encode xsd float value as the xsd:float schema type
typedef long xsd int; // encode xsd int value as the xsd:int schema type
typedef bool xsd boolean; // encode xsd boolean value as the xsd:boolean schema type
typedef unsigned long long xsd positiveInteger; // encode xsd positiveInteger value as the
// xsd:positiveInteger schema type
...
这种简单的机制使得gSOAP soapcpp2工具在进行序列化和反序列化时可以直接对C++类型和XSD类型进行转换。