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
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Problems in connecting and parse response in QtSoap

[ Edited ]

Hi all,

After much research I decided to use QtSoap to intergrate with the web service. But I have zero knowledge in web service. So i need some help in order to get the response.

I'm given a wsdl link looks smt like this http://175.143.53.21:9081/CCWS/MiBWSServices?wsdl

and there're alot of methods inside.

for example, one of the method to call performLogin.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:adap="http://adapter.ccws.jessica.com/">
 <soapenv:Header>
       <security xmlns="http://security.ccws.jessica.com/">
         <appversion>1.0</appversion>
         <id>soapui123</id>
         <make>Apple</make>
         <model>iPhone 5</model>
         <type>x</type>
         <os>ios7</os>
         <csrf_token>abc123</csrf_token>
      </security>
</soapenv:Header>
   <soapenv:Body>
      <adap:performLogin>
         <!--Optional:-->
         <loginID></loginID>
         <!--Optional:-->
         <password></password>
      </adap:performLogin>
   </soapenv:Body>
</soapenv:Envelope>

 below is how i request and response. I manually inserted the header but I'm not sure what should i put for the setAction, setHost, submitRequest to where.

void WebService::requestLoginInformation(const QString &username,
		const QString &password) {

	m_soap.setAction("http://175.143.53.21:9081/CCWS/MiBWSServices/performLogin");
	m_soap.setHost("http://175.143.53.21:9081/");

	//////////////////////

	QtSoapMessage request;

	QtSoapStruct *soap_struct = new QtSoapStruct(QtSoapQName("security", "http://security.ccws.hlb.silverlake.com/"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("appversion"), "1.0"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("id"), "soapui123"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("make"), "Apple"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("model"), "iPhone 5"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("type"), "x"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("os"), "ios7"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("csrf_token"), "abc123"));

	request.addHeaderItem(soap_struct);

	request.setMethod(QtSoapQName("performLogin", "http://175.143.53.21:9081/CCWS/MiBWSServices/"));

	request.addMethodArgument("loginID", "", username);
	request.addMethodArgument("password", "", password);

	// Submit the method request to the web service.
	m_soap.submitRequest(request, "http://175.143.53.21:9081/CCWS/MiBWSServices?wsdl");
}
//! [1]

/**
 * WebService::onServiceResponse()
 *
 * SLOT
 * Called when the SOAP interface returns a response
 * Retrieves the SOAP result, sets member variables and
 * emits a signal indicating the request is complete
 */
//! [2]
void WebService::onServiceResponse() {
	// Get the response, check for error.
	const QtSoapMessage& response = m_soap.getResponse();
	if (response.isFault()) {
		m_error = tr("Query failed: %1").arg(
				response.faultString().value().toString());
		emit statusChanged();

		m_active = false;
		emit activeChanged();

		emit complete();
		return;
	}

	const QtSoapType &res = response.returnValue();

	// Extract the return value from this method response, check for
	// errors.
	const QtSoapType& responseValue = res["obHeader"];

	if (QString::compare("MIB.0000001", responseValue["statusCode"].toString(),
			Qt::CaseInsensitive) == 0) {
		m_succeeded = true;
		m_error.clear();

		m_statusCode = responseValue["statusCode"].toString();
		m_statusMessage = responseValue["statusMessage"].toString();

		emit statusCodeChanged();
		emit statusMessageChanged();
	} else {
		m_succeeded = false;
		m_error = responseValue["statusMessage"].toString();
	}

	emit statusChanged();

	m_active = false;
	emit activeChanged();

	emit complete();
}

 this is the flow of the response.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
      <security xmlns="http://security.ccws.hlb.silverlake.com/">
         <csrf_token>abc123</csrf_token>
      </security>
   </soap:Header>
   <soap:Body>
      <ns2:performLoginResponse xmlns:ns2="http://adapter.ccws.hlb.silverlake.com/">
         <return xsi:type="ns2:obAuthenticationResponse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <obHeader>
               <statusCode>MIB.0000001</statusCode>
               <statusMessage>device is not tag yet</statusMessage>
            </obHeader>
            <obUser>
               <fullName>Jessica</fullName>
            </obUser>
            <userContext>
               <loginId>jess01</loginId>
               <sessionId>d44bc90f-1063-11e3-be19-cd77a9313c0e</sessionId>
            </userContext>
         </return>
      </ns2:performLoginResponse>
   </soap:Body>
</soap:Envelope>

 But i'm not getting anything back. It seems like the request has failed. Any idea or guides on where i did wrong?

Any help will be much appreciatedSmiley Happy

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problems in connecting and parse response in QtSoap

did you check out the sample on github?

to submit a request i use
m_soap.submitRequest(networkReq, request, configUrl.path());
with networkReq being a NetworkRequest (no need to do anything with it unless you want cookie management, ssl, raw headers or similar), request being QtSoapMessage.

you call setAction on the QtSoapHttpTransport to set the method of your server, in your case performLogin. On the transport you also use setHost to set the server url.

Using request.toXmlString(0) you can get a trace of the request, i use soapUI to compare this to the needed structure.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: Problems in connecting and parse response in QtSoap

I'm actually referring to soapxml in github.

can i know what is the configUrl.path() that you're saying?

and i got an error message (not sure where the http://:80 comes from)

Invalid URL: http://:80/http://175.143.53.21:9081/CCWS/MiBWSServices?wsdl

 

in my request, i set like this:

m_soap.setAction("performLogin");
m_soap.setHost("http://175.143.53.21:9081/");

 

request.setMethod(QtSoapQName("performLogin", "http://175.143.53.21:9081/CCWS/MiBWSServices/"));

request.addMethodArgument("loginID", "", username);
request.addMethodArgument("password", "", password);

 

 

m_soap.submitRequest(request, "http://175.143.53.21:9081/CCWS/MiBWSServices?wsdl");

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problems in connecting and parse response in QtSoap

configUrl is a QUrl object with the server address.
your submitRequest call is wrong, it needs only the path as the parameter.
the host (and port) are set on the QtSoapHttpTransport using setHost.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: Problems in connecting and parse response in QtSoap

sorry that I'm a little slow in catching up these stuffs.

Correct  me if I'm wrong.

 

for the below code, I got a fault for the return value when i do this in onServiceResponse()

const QtSoapMessage& response = m_soap.getResponse();
qDebug() << response.toXmlString(0);

 

so i'm passing nothing when doing the submit request, did i call wronly again for the submitRequest? Smiley Sad

 

void WebService::requestLoginInformation(const QString &username,
		const QString &password) {
	if (m_active)
		return;

	m_active = true;
	emit activeChanged();

	m_succeeded = false;

	m_soap.setAction("performLogin");
	m_soap.setHost("175.143.53.21", 9081);

	//////////////////////

	QtSoapMessage request;

	QtSoapStruct *soap_struct = new QtSoapStruct(QtSoapQName("security", "http://security.ccws.hlb.silverlake.com/"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("appversion"), "1.0"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("id"), "soapui123"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("make"), "Apple"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("model"), "iPhone 5"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("type"), "x"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("os"), "ios7"));
	soap_struct->insert(new QtSoapSimpleType(QtSoapQName("csrf_token"), "abc123"));

	request.addHeaderItem(soap_struct);

	request.setMethod(QtSoapQName("performLogin", "http://175.143.53.21:9081/CCWS/MiBWSServices/"));

	request.addMethodArgument("loginID", "", username);
	request.addMethodArgument("password", "", password);

	// Submit the method request to the web service.
	m_soap.submitRequest(request, "/CCWS/MiBWSServices?wsdl");

	qDebug() << "end of submit request....";
}

 

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problems in connecting and parse response in QtSoap

the first step would be (for me) to check if the request you generate is correct. before sending it call
qDebug() << request.toXmlString(0);

you can also monitor the connection by using tcpmon. this allows you to see what your server returns.

at a glance i suspect that your setMethod call does not use the namespace you need, at least your soap struct gets a different one.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: Problems in connecting and parse response in QtSoap

it seems like the request is correct, as it prints out the way i expected to be:

so now my guess the problem is from submitRequest .... and i dont have any idea of what i should put there?

"<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:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<security xmlns="http://security.ccws.hlb.silverlake.com/">
<appversion xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">1.0</appversion>
<id xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">soapui123</id>
<make xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">Apple</make>
<model xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">iPhone 5</model>
<type xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">x</type>
<os xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">ios7</os>
<csrf_token xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">abc123</csrf_token>
</security>
</SOAP-ENV:Header>
<SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<performLogin xmlns="http://175.143.53.21:9081/CCWS/MiBWSServices/">
<loginID xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">Hlb01</loginID>
<password xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">Xxx</password>
</performLogin>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
" 

 

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problems in connecting and parse response in QtSoap

copy this into soapUI and execute it, does it work?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: Problems in connecting and parse response in QtSoap

currently the server i'm working on is down so unable to test it out whether it works or not.

but in a mean time i have a question for tat...

from soapUi i got this line

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:adap="http://adapter.ccws.hlb.silverlake.com/">

 

however, from the request.toXmlString(0); 

i realized that the adapter is missing

<SOAP-ENV:Envelope xmlnsSmiley FrustratedOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">

does this causes a problem too?

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problems in connecting and parse response in QtSoap

doesn't have to. soapui uses forward declaration for namespaces and uses only the defined shorthand (adap) later on.
qtsoap does not have this fancy stuff and uses the namespace on every element. wastes quite some space, but works fine otherwise.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter