我正在尝试开发一个可以通过 OPC XML-DA 规范访问数据的肥皂客户端:这里
我使用 gSOAP 提供的工具从 OPC Foundations WSDL 生成 gSOAP 头文件。(以下相关部分)
我似乎无法让 gSOAP 正确地向标签添加属性。(见下面的输出部分)。是否有内置的方法来执行此操作,或者是否需要修改 WSDL/gSOAP 标头?
WSDL 提取:
<s:complexType name="ItemValue">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="DiagnosticInfo" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="Value" />
<s:element minOccurs="0" maxOccurs="1" name="Quality" type="s0:OPCQuality" />
</s:sequence>
<s:attribute name="ValueTypeQualifier" type="s:QName" />
<s:attribute name="ItemPath" type="s:string" />
<s:attribute name="ItemName" type="s:string" />
<s:attribute name="ClientItemHandle" type="s:string" />
<s:attribute name="Timestamp" type="s:dateTime" />
<s:attribute name="ResultID" type="s:QName" />
</s:complexType>
生成的 gSOAP 标头
class ns1__ItemValue
{ public:
/// Element DiagnosticInfo of type xs:string.
char* DiagnosticInfo 0; ///< Optional element.
/// Element 'Value' has no type or ref: assuming XML content.
_XML Value 0; ///< Optional element.
/// Element Quality of type "http://opcfoundation.org/webservices/XMLDA/1.0/":OPCQuality.
ns1__OPCQuality* Quality 0; ///< Optional element.
/// Attribute ValueTypeQualifier of type xs:QName.
@_QName ValueTypeQualifier 0; ///< Optional attribute.
/// Attribute ItemPath of type xs:string.
@char* ItemPath 0; ///< Optional attribute.
/// Attribute ItemName of type xs:string.
@char* ItemName 0; ///< Optional attribute.
/// Attribute ClientItemHandle of type xs:string.
@char* ClientItemHandle 0; ///< Optional attribute.
/// Attribute Timestamp of type xs:dateTime.
@time_t* Timestamp 0; ///< Optional attribute.
/// Attribute ResultID of type xs:QName.
@_QName ResultID 0; ///< Optional attribute.
/// A handle to the soap struct that manages this instance (automatically set)
struct soap *soap ;
};
生成的代码
class SOAP_CMAC ns1__ItemValue
{
public:
char *DiagnosticInfo; /* optional element of type xsd:string */
char *Value; /* optional element of type xsd:anyType */
class ns1__OPCQuality *Quality; /* optional element of type ns1:OPCQuality */
char *ValueTypeQualifier; /* optional attribute */
char *ItemPath; /* optional attribute */
char *ItemName; /* optional attribute */
char *ClientItemHandle; /* optional attribute */
time_t *Timestamp; /* optional attribute */
char *ResultID; /* optional attribute */
struct soap *soap; /* transient */
public:
virtual int soap_type() const { return 18; } /* = unique id SOAP_TYPE_ns1__ItemValue */
virtual void soap_default(struct soap*);
virtual void soap_serialize(struct soap*) const;
virtual int soap_put(struct soap*, const char*, const char*) const;
virtual int soap_out(struct soap*, const char*, int, const char*) const;
virtual void *soap_get(struct soap*, const char*, const char*);
virtual void *soap_in(struct soap*, const char*, const char*);
ns1__ItemValue() : DiagnosticInfo(NULL), Value(NULL), Quality(NULL), ValueTypeQualifier(NULL), ItemPath(NULL), ItemName(NULL), ClientItemHandle(NULL), Timestamp(NULL), ResultID(NULL), soap(NULL) { }
virtual ~ns1__ItemValue() { }
};
输出
<ns1:Items
ClientItemHandle="Channel1.Device1"
ItemName="Channel_1.Device_1.Tag_1"
ValueTypeQualifier="xsd:unsignedInt">
<Value
xmlns="http://opcfoundation.org/webservices/XMLDA/1.0/">
5
</Value>
</ns1:Items>
需要的输出
<ns1:Items
ClientItemHandle="Channel1.Device1"
ItemName="Channel_1.Device_1.Tag_1"
ValueTypeQualifier="xsd:unsignedInt">
<Value
xmlns="http://opcfoundation.org/webservices/XMLDA/1.0/"
xsi:Type="xsd:unsignedInt">
5
</Value>
</ns1:Items>
输出是指生成并通过线路发送到远程服务器的 XML。