Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
raju504
Posts: 86
Registered: ‎05-21-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: IDEA
Accepted Solution

How to set soap headers in soap request using qtsoap?

Hi All!

 

      I required to add a soap header to the soap request. I am using qtsoap to post soap request. This is my complete request. How can I add headers in code...!

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <SecureSoapHeader xmlns="http://tempuri.org/">
      <Platform>string</Platform>
      <AuthToken>string</AuthToken>
    </SecureSoapHeader>
  </soap:Header>
  <soap:Body>
    <GetCitiesByCountryCode xmlns="http://tempuri.org/">
      <countryCode>string</countryCode>
    </GetCitiesByCountryCode>
  </soap:Body>
</soap:Envelope>

 I tried like this:

QtSoapMessage request;


	QtSoapStruct soap_struct(QtSoapQName("SecureSoapHeader", "http://tempuri.org/"));
soap_struct.insert(new QtSoapSimpleType(QtSoapQName("Platform"), "BlackBerry"));
	soap_struct.insert(new QtSoapSimpleType(QtSoapQName("AuthToken"), "4A2EDCDA-E5A9-4E77-B41A-F1C1FF15A645"));

	request.addHeaderItem(&soap_struct);

	request.setMethod("GetCitiesByCountryCode", "http://tempuri.org/");

	request.addMethodArgument("countryCode", "", "IN");
	http.setHost("dev4.winitsoftware.com");
	http.setAction("http://tempuri.org/GetCitiesByCountryCode");
	http.submitRequest(request, "/EzeegoMiddleware/Services/HotelService.asmx");

 After specifying this the application is closing...

 

If any one tried this, help me please!

 

Thanks.

- Raju

- Raju
Please use plain text.
Developer
Zmey
Posts: 1,507
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: How to set soap headers in soap request using qtsoap?

[ Edited ]

Hi! I did not use this API but I assume submitRequest is asynchronous.

 

You are creating soap_struct on the stack (so it's a local variable).

 

After submitRequest method is called the function will terminate and all local variables will be destroyed, so the address passed to addHeaderItem will become invalid.

 

Try creating soap_struct on the heap:

QtSoapStruct *soap_struct = new QtSoapStruct(...)
soap_struct->insert(...);
request.addHeaderItem(soap_struct);
 

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
raju504
Posts: 86
Registered: ‎05-21-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: IDEA

Re: How to set soap headers in soap request using qtsoap?

Thanks Zmey! It worked... can I know when do we create objects in stack or heap?

- Raju
Please use plain text.
Developer
Zmey
Posts: 1,507
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: How to set soap headers in soap request using qtsoap?

Local variables (created on stack) will be destroyed automatically after exit from a block (or function) in which they were created. This is convenient for temporary objects, but be careful not to pass an address of such object to another object which can try to use it later.

 

When creating objects on heap they must be destroyed explicitly otherwise memory leaks will occur:
MyObject *o = new MyObject;
...
delete o;

 

But in Qt it's usually best to create objects on heap, but set another object as their parent so they will be destroyed automatically when their parent is destroyed:

SomeWidget *w = new SomeWidget(this); // set 'this' as widget's parent. When 'this' is deleted, 'w' will be deleted too

setParent method does the same.

Object must be a QObject descendent for this to work.

 

In the case above I don't see the parent property, but most likely QtSoapMessage will take ownership of the object and will destroy it later although docs don't mention that...

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
raju504
Posts: 86
Registered: ‎05-21-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: IDEA

Re: How to set soap headers in soap request using qtsoap?

Its great to know about the memory management techniques..! If I create more no of objects in the heap in a method, then should I set their parent as the present class object so that they will be deleted with the class object?

(OR)

Is there any way to clear the memory blocks occupied by those memory blocks....?

 

And onething I am not able to capture is, the exact use of class's destructor....! can you give a link for this concept..!

- Raju
Please use plain text.