2012-02-09 79 views
0

我已經構建了一個PHP soap函數,接收一個字符串數組數組,並將其寫入文件。通過gSoap發送多維stl :: vector或數組

這裏是SOAP服務器的WSDL文件:

This XML file does not appear to have any style information associated with it. The  document tree is shown below. 
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="ADRESSE_WEBSERVICE"  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap- enc="http://schemas.xmlsoap.org/soap/encoding/"  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="BoWS"  targetNamespace="ADRESSE_WEBSERVICE"> 
<types> 
<xsd:schema targetNamespace="ADRESSE_WEBSERVICE"/> 
</types> 
<portType name="BoWSPort"> 
<operation name="writeArray"> 
<documentation>This method count and write an array</documentation> 
<input message="tns:writeArrayIn"/> 
<output message="tns:writeArrayOut"/> 
</operation> 
</portType> 
<binding name="BoWSBinding" type="tns:BoWSPort"> 
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
<operation name="writeArray"> 
<soap:operation soapAction="ADRESSE_WEBSERVICE#writeArray"/> 
<input> 
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="ADRESSE_WEBSERVICE"/> 
</input> 
<output> 
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="ADRESSE_WEBSERVICE"/> 
</output> 
</operation> 
</binding> 
<service name="BoWSService"> 
<port name="BoWSPort" binding="tns:BoWSBinding"> 
<soap:address location="ADRESSE_WEBSERVICE"/> 
</port> 
</service> 
<message name="writeArrayIn"> 
<part name="array" type="soap-enc:Array"/> 
</message> 
<message name="writeArrayOut"> 
<part name="return" type="xsd:int"/> 
</message> 
</definitions> 

這個功能才能正常工作,當我通過的soapUI測試這樣的:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="ADRESSE_WEBSERVICE"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <wsdl:writeArray soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
     <SOAP-ENC:Array SOAP-ENC:arrayType="xsd:string[][3]"> 
    <SOAP-ENC:Array id="array-1" SOAP-ENC:arrayType="xsd:string[4]"> 
    <item>26</item> 
    <item>223</item> 
    <item>test</item> 
    <item>test3</item> 
    </SOAP-ENC:Array> 
    <SOAP-ENC:Array id="array-2" SOAP-ENC:arrayType="xsd:string[4]"> 
    <item>26</item> 
    <item>750</item> 
    <item>test</item> 
    <item>test4</item> 
    </SOAP-ENC:Array> 
    <SOAP-ENC:Array id="array-3" SOAP-ENC:arrayType="xsd:string[4]"> 
    <item>70</item> 
    <item>360</item> 
    <item>tes321</item> 
    <item>test23</item> 
    </SOAP-ENC:Array> 
</SOAP-ENC:Array> 
     </wsdl:writeArray> 
    </soapenv:Body> 
</soapenv:Envelope> 

我要發送到功能的multidimensionnal來自C++程序的字符串的數組/向量。

我已經用wsdl2h生成了gSoap頭文件和函數。

該功能的陣列參數是soapStub.h文件生成的結構:

struct _Struct_3 
{ 
public: 
    char **__ptr; 
    int __size; 
}; 

我的問題是我不知道如何使用結構作爲multidimensionnal陣列。

,我必須插入該陣列是在起源串矢量的矢量:

vector< vector<string> > testArray 

即我可以很容易地轉換爲字符串數組的數組。

+0

您曾經試圖生成交換機使用STL的gSOAP的代碼? (如果我沒有記錯,有一個選項允許你在生成的代碼中啓用或禁用stl。) – utnapistim 2012-02-09 10:51:07

回答

0

這個WSDL的問題是沒有數組及其元素的類型信息,只是對通用「soap-enc:Array」的引用。

運行wsdl2h後,更改.h文件這個聲明所產生於:

struct _Struct_3 
{ 
    std::string *__ptr; 
    int __size[2]; // 2D array 
}; 
+0

感謝您的回覆。最後,我提取我的二維矢量字符串的每個元素,並將它們填充到char ** __ptr中。我使用vector [i] * vector [j]大小填充__size,並且它可以正常工作。 – niusha 2012-02-15 15:38:49