2011-03-22 162 views
1

我試圖發送一個SOAP請求到一個接受XML字符串的.NET Webservice。這是存儲在字符數組我的示例XML字符串:通過libcurl向SOAP Web服務發送SOAP請求!

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <BankDeposit xmlns="http://tempuri.org/"> 
    <xmlParam> 
     <onlineTxn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.tempuri.org/"> 
     <TXN> 
      <TxnID>17032011111230</TxnID> 
      <CCID>73467836483</CCID> 
      <ACNO>899000777</ACNO> 
      <TXAMT>52</TXAMT> 
     </TXN> 
    </onlineTxn> 
    </xmlParam> 
    </BankDeposit> 
    </soap12:Body> 
</soap12:Envelope> 

我使用提交到.NET Web服務的代碼如下:

int PostRequest(void) 
{ 
    CURL *curl; 
    char buffer[2000]=//XML String to be sent. 
    int res = -1; 
    struct curl_httppost *post=NULL, *last=NULL; 
    struct curl_slist *headers = NULL; 
    unsigned int buffer_size = 2000; 

    fp = fopen("res.xml","w"); 
    fpreq = fopen ("req.xml", "w"); 

    curl=curl_easy_init(); 
    if(curl) 
    { 
     headers = curl_slist_append(headers, "Content-type:application/soap+xml; charset=utf-8; action=\"http://tempuri.org/BankDeposit\"");  
     curl_easy_setopt(curl, CURLOPT_URL, URL); 
     curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); 
     curl_easy_setopt(curl, CURLOPT_FILE, fp); 
     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); //For writing the responses recieved 
     curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, buffer_size); 
     curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buffer); 

     curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE); 
     curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func);  

     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); 
     curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60); 
     res = curl_easy_perform(curl); 
     curl_slist_free_all(headers); 
     curl_easy_cleanup(curl); 
     printf("CURL Easy Perform Status Code: %d\n", res); 
    } 
    fclose(fp); 
    fclose(fpreq); 
    return res; 
} 

麻煩的是:「內容沒有得到發佈到Web服務「。我調試了我的.NET服務,並沒有收到發件人的任何數據。

我的Webservice操作是:BankDeposit。

接受名爲; xmlParam的類型:字符串

請幫我這個。需要你的建議。

回答

0

使用CURLOPT_DEBUGFUNCTION獲取libcurl發送和接收的完整跟蹤信息。確保請求看起來完全符合你的要求。

您的請求很可能會使libcurl使用「Expect:100-continue」,這是一個通常服務器處理不當的頭文件,因此請嘗試禁用該頭文件。

1

我可以在這裏看到兩個可能的問題:

  1. 你打開兩個文件(使用FOPEN)。如果你使用「w」打開這些文件,你將清除這些文件。
  2. 沒有代碼可以從「現在格式化」的文件中導入數據。

希望這會有所幫助