Dynamic arrays in gSOAP the C++ way, using STL vector instead of __ptr/__size?

£可爱£侵袭症+ 提交于 2019-12-12 15:07:27

问题


I am developing a web service using gSOAP 2.8.8. I would like to send an unbounded sequence of a custom data type. I can implement this by following section 11.11 of gSOAP's User Guide like so:

class ns__InnerType {
  std::string someStr;
  int someInt;
};
class VectorOfInnerTypes {
  ns__InnerType* __ptr;
  int __size;
};
void ns__myMethod(VectorOfInnerTypes in, ns__EmptyResponse out);

This works well. However, since my program is in C++, I would like to take advantage of STL vectors. From everything I've read it appears that gSOAP supports serializing vectors. Here's what I believe should work:

#import "stlvector.h"
class VectorOfInnerTypes {
  std::vector<ns__InnerType> mylist;
};

soapcpp2 is happy to compile this, and I am able to pass a C++ vector when calling the stub's myMethod. However, here's what goes over the network:

<s:Envelope ...>
  <s:Body s:EncodingStyle=...>
    <q1:myMethod xmlns:q1="urn:ns"/>
  </s:Body>
</s:Envelope>

Compare this to the network traffic when I use the __ptr/__size:

<SOAP-ENV:Envelope ...>
  <SOAP-ENV:Body ...>
    <ns:myMethod>
      <mylist xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="ns:InnerType[3]">
        <item>...</item>
        <item>...</item>
        <item>...</item>
      </mylist>
    </ns:myMethod>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

To get std::vector to work, I've tried various combinations of:

std::vector<ns__InnerType> mylist;
std::vector<ns__InnerType*> mylist;
std::vector<ns__InnerType>* mylist;
std::vector<ns__InnerType*>* mylist;

with the requisite soap_new_std__vectorTemplate... and soap_new_ns__InnerType when preparing data on the client, but there's no improvement. It refuses to serialize correctly.

Both when it works (__ptr/__size) and when it doesn't (std::vector), the invocation of myMethod returns code 202, or HTTP Accepted.

How can I, and everyone who uses gSOAP in a C++ program, use STL vectors instead of the primitive __ptr/__size way? Any help would be much appreciated.

来源:https://stackoverflow.com/questions/12538625/dynamic-arrays-in-gsoap-the-c-way-using-stl-vector-instead-of-ptr-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!