PDA

View Full Version : QHttp to Soap Server



xgoan
13th September 2006, 15:31
Can I send a Soap call with QHttp?

I need a example too.

wysota
13th September 2006, 16:02
Yes. Just format a message according to soap rules and issue a request using QHttp.

xgoan
13th September 2006, 18:00
But what url I need to use for:

http://www.esendex.com/secure/messenger/soap/sendservice.asmx

:confused:

wysota
13th September 2006, 21:22
But what url I need to use for:

http://www.esendex.com/secure/messenger/soap/sendservice.asmx

I don't think this qualifies as a Qt-related question... If you looked at the WSDL file provided on that webpage, you'd notice this entry:


<wsdl:service name="SendService">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/">Methods to send SMS messages individually and in batches. Click here for a &lt;a href="https://www.esendex.com/uk/evaluation/evaluation.aspx" title="SMS Service Trial"&gt;free trial&lt;/a&gt;.</documentation>
<wsdl:port name="SendServiceSoap" binding="tns:SendServiceSoap">
<soap:address location="http://www.esendex.com/secure/messenger/soap/sendservice.asmx" />
</wsdl:port>
</wsdl:service>
and everything would be clear...

BTW. If you click on the message name (on the page you mentioned), you'll get an example of a formatted http message needed to access that method:
http://www.esendex.com/secure/messenger/soap/sendservice.asmx?op=SendMessageFull

xgoan
14th September 2006, 20:57
I have done it and works, here is the code to someone else.


bool HttpGet::getFile(const QUrl &url)
{
http.setHost(url.host(), url.port(80));
QByteArray byteArray("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\"> \n"
" <soap:Header>\n"
" <MessengerHeader xmlns=\"com.esendex.ems.soapinterface\">\n"
" <Username>username</Username>\n"
" <Password>password</Password>\n"
" <Account>account</Account>\n"
" </MessengerHeader>\n"
" </soap:Header>\n"
" <soap:Body>\n"
" <SendMessageFull xmlns=\"com.esendex.ems.soapinterface\">\n"
" <originator>dsfs</originator>\n"
" <recipient>telefono</recipient>\n"
" <body>string</body>\n"
" <type>Text</type>\n"
" <validityperiod>24</validityperiod>\n"
" </SendMessageFull>\n"
" </soap:Body>\n"
"</soap:Envelope>\n");
cout<<byteArray.data()<<endl;
http.setHost(url.host());
QHttpRequestHeader header("POST" ,"/secure/messenger/soap/sendservice.asmx");
header.setValue("Host", "www.esendex.com");
header.setValue("Content-Type", "text/xml; charset=utf-8");
header.setValue("SOAPAction", "com.esendex.ems.soapinterface/SendMessageFull");
http.request(header,byteArray,&file);
http.close();
return true;
}

rohan_m_e
5th December 2008, 06:59
hi,
if u want to retrieve the object from the soap message then how do u do it?
thanks

wysota
6th December 2008, 09:02
What do you mean by "the object"? What object?

rohan_m_e
9th December 2008, 06:45
the object is nothing but the data in the soap response. eg : temperature from the response given by the weather web service. how can i retrieve it?

patrik08
9th December 2008, 10:20
I suppose you must only one time login && at end logout...

after login you send only the session ID





SoaRequest::SoaRequest( QObject * parent )
: QObject( parent )
{
setObjectName(QString::fromUtf8("SoaRequest"));
Cache(WORK_TICINO_SESSION);
ResetSession();
currentID = -1;
Save_append_Session(); ///// login and start request /////
}

void SoaRequest::Login()
{
qDebug() << "### soa Login ACTION ###################";
QString Stream_0 ="PD94bWw.........U+";
QString Stream = fromBase64(Stream_0);
Stream = Stream.replace("_PASS_",decodeBase64(setter.value("tijava/pass").toString()));
Stream = Stream.replace("_USER_",decodeBase64(setter.value("tijava/user").toString()));
ResetSession(); /////// save _SESSION_ or die
Send(Stream,_URLSYSTEM_,1);
}

void SoaRequest::Logout()
{
qDebug() << "### soa Logout ACTION ###################";
QString Stream_0 ="PD94bWwgdmVyc2..........lPg==";
QString Stream = fromBase64(Stream_0);
Stream = Stream.replace("_SESSION_",WebSessionCurrent);
qDebug() << "### soa logout -> " << WebSessionCurrent;
Send(Stream,_URLSYSTEM_,0);
ResetSession();
}



after you write a QNetworkAccessManager login send request and logout
similar from:
http://fop-miniscribus.googlecode.com/svn/trunk/doc/remote_cache/

To debug webservice i write a small debugger:
http://www.qt-apps.org/content/show.php/Http+Debugger++qt4.3.3?content=76432


I try your url and i send on my debugger :



<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<soap:Header>
<MessengerHeader xmlns="com.esendex.ems.soapinterface" >
<Username>bill88</Username>
<Password>sgsd2352</Password>
<Account>235235</Account>
</MessengerHeader>
</soap:Header>
<soap:Body>
<SendMessageFull xmlns="com.esendex.ems.soapinterface" >
<originator>sxdgsdgssg</originator>
<recipient>sdfgsdgsd</recipient>
<body>hello world</body>
<validityperiod>30</validityperiod>
</SendMessageFull>
</soap:Body>
</soap:Envelope>


the response:




----------------------send request------------------------------------
ValueName Content-Type = text/xml; charset=utf-8
ValueName Host = www.esendex.com
ValueName SOAPAction = com.esendex.ems.soapinterface/SendMessageFull
ValueName User-Agent = DevNavigator
----------------------send end------------------------------------
----------------------incomming header----------------------------
Header responds = 500
date=Tue, 09 Dec 2008 10:36:21 GMT
server=Microsoft-IIS/6.0
x-powered-by=ASP.NET
x-aspnet-version=2.0.50727
cache-control=private
content-type=text/xml; charset=utf-8
content-length=476


<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Authentication Failed ---> Authentication Failed</faultstring>
<detail>
<ErrorCode>2</ErrorCode>
<ErrorMessage>Authentication Failed</ErrorMessage>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>





Also autenfication and message all inside one xml and ommit tipe accept default

wysota
9th December 2008, 10:53
how can i retrieve it?

If you are crafting the request structure manually, then you have to manually parse the response and take the xml tag text you need.