L
L
lemon_spb2013-05-23 12:46:53
Qt
lemon_spb, 2013-05-23 12:46:53

How to compose a SOAP message correctly? (C++ Qt)?

Good afternoon, help, please, dear Khabrovites!
I'm trying to understand SOAP.
You need to write a message according to the template.
I am using Qt Creator. Installed QtSoap. Test messages are compiled and sent, for example:

QtSoapMessage request;

    request.setMethod("procedure", ""); // Вызываемая процедура

    QtSoapArray * array = new QtSoapArray(QtSoapQName("arrayName"), QtSoapType::Array, 2);

    QtSoapStruct * struct1 = new QtSoapStruct(QtSoapQName("testName"));
    array->append(struct1);

    QtSoapStruct * struct2 = new QtSoapStruct(QtSoapQName("testName"));
    array->append(struct2);

    request.addMethodArgument(array);

    this->send(request); //отправляем, используя QtSoapHttpTransport

Here is what comes to the server:
<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <procedure>
    <arrayName
      SOAP-ENC:arrayType="xsd:struct[2]"
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xsi:type="xsd:Array"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    >
      <item SOAP-ENV:position="[0]" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
      <item SOAP-ENV:position="[1]" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
    </arrayName>
  </procedure>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

What's wrong here:
1. In the first "SOAP-ENV:Envelope" tag, the links are not quite the same. In it, you need to add more parameters of all your types xmlns: *** = " http://***"
2. In the Body tag, you need to remove all parameters.
3. The procedure tag needs the SOAP-ENV:encodingStyle = " http://***"
attribute 4. The arrayName tag needs the xsi:type = "SOAP-ENC:Array" attribute
5. Ibid SOAP-ENC:itemType = "***"
6. In the same place SOAP:ENC:arraySize = "***"
7. Remove all tags from each array element.
Here is the QtSoap doc doc.qt.digia.com/solutions/4/qtsoap/index.html
there is even an example.
Various QtSoapType::setHref/setId don't help and probably shouldn't.
For the life of me, I did not find anything there that would help me in these matters.
You can probably compose the XML yourself and give it to be torn to pieces in request:
QtSoapMessage request;
    QDomDocument document;
    //составляем XML
    request.setContent(document);//запихиваем в request
    //отправляем

then we get something like this (if the document is not filled out at all)
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema"/>

But in this case, the question remains, how to add your attributes to the main tag.
And in general, this is probably wrong and rather tedious to compose SOAP messages by hand.
Or maybe they gave me a curved sample?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2013-05-23
@RedOctoberCZ

Try using the gSOAP Toolkit , maybe it will help you figure it out. Or Qt SOAP Manager .

K
kxyu, 2013-05-23
@kxyu

Qt SOAP is not entirely native, it is included in Qt Solutions (it is not included in Qt, the situation with support is not entirely clear). In my experience, the degree of compatibility of various SOAP implementations is close to zero - that is, if you have a .NET service and a .NET client, then maybe everything will work as it should. Therefore, manually generating requests is the easiest and most reliable way. Parse, respectively, also manually, for example, using xpath.
This does not cause any particular problems, since the code for generating and parsing a message is quite abstract and is written once.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question