2011-09-09 8 views
4

私はいくつかのリクエストタイプを持っています。これは本当にenumです。xmlでenumを実行する方法

しかし、私のコードでこれらの要求タイプが列挙されている:WSDLファイルで

enum RequestType { 
    RequestRegister, 
    RequestUnregister, 
    etc 
}; 

私の現在の試みは以下の通りです。しかし、文字列型を使用します。私のサーバーでは、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> 

追加の注記。

クライアントはxmlメッセージのみを送信できます(これを制御することはできません)ので、xmlを使用するのは強制的です。しかし、私はクライアントが使用するXMLを構成します。私が管理している/書いているサーバはC++で書かれており、libxmlを使ってxmlファイルの 'parts'を抽出しています。理想的には、項目はintまたはenumです。これを行うには、たとえば、

// xmlからアイテムを列挙型またはintに抽出したいからです。 RequestType rqtype = getRequestType();

switch(rqtype) { 
case RequestMakeCall: 
    //do whatever 

上記の場合、RequestTypeは列挙型です。文字列値を抽出し、関連する列挙型値の参照を行う必要があります。効率的ではありません。

私が見ているenumのすべての例は、文字列を使用しているようですが、これは奇妙に見えます。

+0

私は列挙型として文字列を表現することははるかに自然だと思います。これにより、XMLと解析コードが読みやすくなります。また、パフォーマンスの違いはおそらく重要ではありません。ライブラリと解析コードはすでに文字列で処理されているため、もう少しそれを害することはありません。値を読み取る速度が重要な場合は、XMLを使用しないでください。 – svick

答えて

3

独自の型を作成することができます

<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> 
+0

おそらく私は制限ベースが文字列であると少し混乱しています。制限ベース= "文字列"は単に列挙型の名前が文字列であることを意味しますか?すべての名前は文字列ですか?私の受信機コードでは、私はlibxmlを使用します。私の懸念は、libxmlがOperatingSystemVersionをどのように抽出するかということです。 libxmlがenum値にどのように対応しているかを調べる必要がありますか? –

+0

''は次のように言っています:型は文字列ですが、これらの追加の制限があります。ええ、名前が文字列であるとはかなり言われています。私はあなたがlibxmlで何をする必要があるか分かりません。私はそれを使ったことはありません。 – svick

+0

エレメント属性の代わりにタイプ別にパートエレメントを指定する場合は注意が必要です。そのため、親ノードの名前空間は(修飾されたノードの子要素とは対照的に)指定されず、その名前空間定義が解釈に開放されたままになり、相互運用性の問題が発生する可能性があります。 – Eduardo

関連する問題