Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > С/С++: Кроссплатформенное программирование, Qt/Gtk+/wxWidgets > QtSoap-client + web-service .NET


Автор: Greeneyed 3.6.2011, 16:16
Есть клиент на Qt, который должен работать с веб-сервисами.

Код

void WebDataProvider::callWebService()
{
    connect(&http, SIGNAL(responseReady(QtSoapMessage)), this, SLOT(getResponse(QtSoapMessage)));

    http.setHost("xxx.xxx.xxx", 80);
    http.setAction("http://tempuri.org/SendMessage");


    QtSoapMessage request;
    request.setMethod(QtSoapQName("SendMessage", "htpp://tempuri.org/"));

    request.addMethodArgument("From", "", "bla-bla-bla");
    request.addMethodArgument("To", "", "bla-bla-bla" );
    request.addMethodArgument("Subject", "", "mysubject");
    request.addMethodArgument("Body", "", "bodydydy");


    // Submit the method request to the web service.
    http.submitRequest(request, "/WebService.asmx");

    qDebug() << request.toXmlString();
}
//-------------------------------------------------------------

void WebDataProvider::getResponse(QtSoapMessage mes)
{
    const QtSoapType &res = mes.returnValue();
    qDebug("\n\n\n");
    qDebug() << mes.toXmlString();
}


Запрос к сервису уходит, а в ответ от сервиса приходит "From is null". То есть сервис запускается, но параметры ему не передаются.
Сервис выглядит вот так.

Код

POST /MedExWebService.asmx HTTP/1.1
Host: xxx.xxx.xxx
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/SendMessage"

<?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:Body>
    <SendMessage xmlns="http://tempuri.org/">
      <From>string</From>
      <To>string</To>
      <Subject>string</Subject>
      <Body>string</Body>
    </SendMessage>
  </soap:Body>
</soap:Envelope>



HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?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:Body>
    <SendMessageResponse xmlns="http://tempuri.org/">
      <SendMessageResult>string</SendMessageResult>
    </SendMessageResponse>
  </soap:Body>
</soap:Envelope>

Автор: Greeneyed 6.6.2011, 10:20
Особо подходящего решения не нашел. Есть вариант использовать gSOAP, но публиковать исходники не хочется, а на покупку пока нет денег.
Решил написать свой небольшой класс, который формирует post-запросы к сервису, а потом парсит ответ. Благо, работа с XML в Qt несложная.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)