2011-09-16 6 views
0

SOAP要求をWebサービスに送信し、Cを使用して応答を返そうとしています。私は "simplepost.c"の例に向けて、これを使用して、私のコマンドラインでWebサービスからSOAP応答を返すことができます。しかし、画面にレスポンスを表示する代わりに、レスポンス文字列を処理したいので、SOAPタグ内の値を抽出することができます。私は以下の送受信プログラムを書いていますが、適切な応答を受け取ることができません。これは、送信または受信に問題があることを意味します。もし私がどの程度正確に達成できるかを見つけ出すことができれば、本当に役に立ちます。前もって感謝します。SOAP応答文字列のハンドルについて

マイコード:

#include <stdio.h> 
#include <string.h> 
#include <curl/curl.h> 

/* Auxiliary function that waits on the socket. */ 

int main(void) 
{ 
    CURL *curl; 
    CURLcode res; 
    /* Minimalistic http request */ 
    const char *request = "<?xml version=\"1.0\" encoding=\"utf-8\"?> <S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"xmlns:tns=\"http://ThermodynamicProperties/\"><S:Body> <tns:getSpeciesInformation> <speciesSymbol>CO2</speciesSymbol> <phase>GAS</phase> </tns:getSpeciesInformation> </S:Body> </S:Envelope>"; 

size_t iolen; 

    struct curl_slist *headerlist=NULL; 
    curl = curl_easy_init(); 
    if(curl) { 
    curl_easy_setopt(curl, CURLOPT_URL, "http://thermo.sdsu.edu/servlet/ThermodynamicProperties/ThermodynamicPropertiesService"); 

    /* Do not do the transfer - only connect to host */ 
    curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); 


    res = curl_easy_perform(curl); 

    if(CURLE_OK != res) 
    { 
     printf("Error: %s\n", strerror(res)); 
     return 1; 
    } 

curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); 
    curl_easy_setopt(curl, CURLOPT_POST, 1); 
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request); 
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); 

    puts("Sending request."); 
    /* Send the request. Real applications should check the iolen 
    * to see if all the request has been sent */ 
    res = curl_easy_send(curl,request, strlen(request), &iolen); 

    if(CURLE_OK != res) 
    { 
     printf("Error: %s\n", curl_easy_strerror(res)); 
     return 1; 
    } 
    puts("Reading response."); 

    /* read the response */ 

printf("ok1 \n"); 
     char buf[10240]; 
    res = curl_easy_recv(curl, buf, 10240, &iolen); 
printf("ok2 \n"); 
     if(CURLE_OK != res) 

    { 
printf("Error: %s\n", strerror(res)); 

     } 
else{ printf("data %s \n", buf); 


    } 

    /* always cleanup */ 
    curl_easy_cleanup(curl); 
    } 
    return 0; 
} 

私は取得しています応答は次のとおりです。 送信要求。 応答を読み取ります。 OK1 OK2 エラー:a.outの中の.libセクションでは、

答えて

0

を破損し、すべての送信が/パートを受信して​​も、SOAPメッセージを解析し、構築して、それが扱っているので、私は、あなたがgsoapを使用してお勧めします。

あなたが間違ったコンテントタイプを持っていることを確実にするために、カールと手作業による解析をしたい場合。これは、SOAP 1.2で

Content-Type:text/xml 
SOAP 1.1で

または

なければならないと私は正しいコンテンツタイプすることなく、多くのウェブサービスにも対応していないことを見てきました。

本当にツールを使ってスタブを生成し、プログラムのロジックに焦点を当ててみてください。手でパースを書くのは一般的に悪いです。

関連する問題