【问题标题】:Sending SOAP Request to .NET Web Service via libcurl!通过 libcurl 向 .NET Web 服务发送 SOAP 请求!
【发布时间】:2011-03-22 11:08:54
【问题描述】:

我正在尝试向接受 XML 字符串的 .NET Web 服务发送 SOAP 请求。这是我存储在 char 数组中的示例 XML 字符串:

<?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 网络服务的代码如下:

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 服务,但它没有收到来自发件人的任何数据。

我的 Web 服务操作是:BankDeposit。

接受一个名为 ; 的参数类型的xml参数:字符串

请帮我解决这个问题。需要你的建议。

【问题讨论】:

    标签: .net curl libcurl


    【解决方案1】:

    我可以在这里看到两个可能的问题:

    1. 您打开两个文件用于写入(使用 fopen)。如果使用“w”打开文件,则会清除文件。
    2. 没有从“现在格式化”文件中导入数据的代码。

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      使用 CURLOPT_DEBUGFUNCTION 获取 libcurl 发送和接收内容的完整跟踪。确保请求看起来完全符合您的要求。

      您的请求可能使 libcurl 使用“Expect: 100-continue”,这是一个经常被服务器处理不当的标头,因此请尝试禁用它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多