我有很多请求类型-确实是枚举。
但是在我的代码中,这些请求类型是一个枚举:
enum RequestType {
RequestRegister,
RequestUnregister,
etc
};
Run Code Online (Sandbox Code Playgroud)
我当前对wsdl文件的尝试如下。但是它使用字符串类型。在我的服务器中,我需要从xml中提取一个enum / 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>
Run Code Online (Sandbox Code Playgroud)
附加说明。
我被“强制”使用xml,因为客户端只能发送xml消息(对此无法控制)。但是我组成了客户端使用的xml。我可以控制/写入的服务器是用C ++编写的,并且我正在使用libxml提取xml文件的“部分”。理想情况下,该项目是int或enum。因为我想这样做:
//从xml提取项目-枚举或int RequestType rqtype = getRequestType();
switch(rqtype) {
case RequestMakeCall:
//do whatever
Run Code Online (Sandbox Code Playgroud)
在上述情况下,RequestType是一个枚举。提取字符串值然后查找相关的枚举值效率不高。
我看到的所有枚举示例似乎都使用字符串,这似乎很奇怪。
您可以创建自己的类型:
<definitions targetNamespace="http://www.iteloffice.com/wsdl/cubacti.wsdl"
xmlns:tns="Mediaresearch.SimNet.Communication"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<s:schema elementFormDefault="qualified"
targetNamespace="http://www.iteloffice.com/wsdl/cubacti.wsdl">
<s:simpleType name="OperatingSystemVersion">
<s:restriction base="s:string">
<s:enumeration value="None" />
<s:enumeration value="WinXp" />
<s:enumeration value="WinVista" />
<s:enumeration value="Win7" />
</s:restriction>
</s:simpleType>
</s:schema>
</types>
<message name="OperatingSystemVersion">
<part name="user_name" type="tns:OperatingSystemVersion" />
</message>
</definitions>
Run Code Online (Sandbox Code Playgroud)