我有許多請求類型 - 這實際上是枚舉。如何在xml中執行枚舉
但在我的代碼,這些請求類型是一個枚舉:
enum RequestType {
RequestRegister,
RequestUnregister,
etc
};
我在WSDL文件當前的嘗試是下面。但它使用一個字符串類型。在我的服務器中,我需要從xml中提取枚舉/ int。對字符串進行查找看起來像是糟糕的設計。
那麼如何形成我的wsdl文件,以便請求類型是枚舉?
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="CubaCTI"
targetNamespace="http://www.iteloffice.com/wsdl/cubacti.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.iteloffice.com/wsdl/cubacti.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="MonitorStartRequest">
<part name="user_name" type="xsd:string" />
<part name="password" type="xsd:string" />
<part name="dn" type="xsd:string"/>
</message>
<message name="MonitorStartResponse">
<part name="errorcode" type="xsd:short"/>
<part name="errormessage" type="xsd:string"/>
</message>
<message name="MonitorStopRequest">
<part name="user_name" type="xsd:string" />
<part name="password" type="xsd:string" />
<part name="dn" type="xsd:string"/>
</message>
<message name="MonitorStopResponse">
<part name="errorcode" type="xsd:short"/>
<part name="errormessage" type="xsd:string"/>
</message>
<message name="MakeCallRequest">
<part name="user_name" type="xsd:string" />
<part name="password" type="xsd:string" />
<part name="dn" type="xsd:string"/>
<part name="destination" type="xsd:string"/>
<part name="userdata" type="xsd:string"/>
</message>
<message name="MakeCallResponse">
<part name="errorcode" type="xsd:short"/>
<part name="errormessage" type="xsd:string"/>
</message>
<message name="ClearConnectionRequest">
<part name="user_name" type="xsd:string" />
<part name="password" type="xsd:string" />
<part name="dn" type="xsd:string"/>
<part name="destinationconnectionid" type="xsd:string"/>
</message>
<message name="ClearConnectionResponse">
<part name="errorcode" type="xsd:short"/>
<part name="errormessage" type="xsd:string"/>
</message>
<portType name="CubaCTIRequests">
<operation name="MonitorStart">
<input message="tns:MonitorStartRequest"/>
<output message="tns:MonitorStartResponse"/>
</operation>
<operation name="MonitorStop">
<input message="tns:MonitorStopRequest"/>
<output message="tns:MonitorStopResponse"/>
</operation>
<operation name="MakeCall">
<input message="tns:MakeCallRequest"/>
<output message="tns:MakeCallResponse"/>
</operation>
<operation name="ClearConnection">
<input message="tns:ClearConnectionRequest"/>
<output message="tns:ClearConnectionResponse"/>
</operation>
</portType>
<binding type="tns:CubaCTIRequests" name="cubactibinding">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="MonitorStart">
<soap:operation soapAction="MonitorStart"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="MonitorStop">
<soap:operation soapAction="MonitorStop"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://www.iteloffice.com/cubctirequests"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://www.iteloffice.com/cubctirequests"
use="literal"/>
</output>
</operation>
<operation name="MakeCall">
<soap:operation soapAction="MakeCall"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="ClearConnection">
<soap:operation soapAction="ClearConnection"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="CubaCTI_Service">
<documentation>WSDL File for Cuba CTI services</documentation>
<port binding="tns:cubactibinding" name="CubaCTIRequestsBinding">
<soap:address
location="http://angusnotebook:8080"/>
</port>
</service>
</definitions>
附加說明。
我'被迫'使用XML,因爲客戶端只能發送XML消息(無法控制這一點)。但我彌補了客戶端使用的xml。我控制/寫的服務器是用C++編寫的,我使用libxml來提取xml文件的'部分'。理想情況下,該項目將是一個int或枚舉。因爲我想要例如這樣做:
//從xml中提取項目 - 變爲枚舉或int RequestType rqtype = getRequestType();
switch(rqtype) {
case RequestMakeCall:
//do whatever
在上述情況下的RequestType是一個枚舉。提取字符串值並且然後必須查找相關的枚舉值是無效的。
我看到的枚舉的所有例子似乎都使用了字符串,這看起來很奇怪。
我想代表字符串作爲枚舉是更自然。它使得XML和解析代碼更具可讀性。任何性能差異可能都無關緊要 - 庫和解析代碼已經必須與字符串一起工作,所以更多一點不會傷害。如果讀取值的速度對您很重要,請勿使用XML。 – svick