简体   繁体   English

Asmx和LibCurl无效的Web服务名称

[英]Asmx and LibCurl invalid webservice name

I have this code to use lib curl to call my asmx webservice. 我有这段代码可以使用lib curl来调用我的asmx Web服务。 It works for my HelloWorld service. 它适用于我的HelloWorld服务。 The asmx webservice is written in Visual Studio 2012. I am attempting to make a restful interface, not SOAP. asmx Web服务是用Visual Studio 2012编写的。我试图创建一个宁静的接口,而不是SOAP。

int main()
{
    CURL *curl;
    CURLcode res;
    curl = curl_easy_init();
    if(curl) 
    {
        curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:14523/Services/Service.asmx/HelloWord");
        curl_easy_setopt(curl, CURLOPT_POST,1);
        std::string content="<request></request>";
        curl_easy_setopt (curl, CURLOPT_POSTFIELDS, content);
        curl_easy_setopt (curl, CURLOPT_POSTFIELDSIZE, strlen (content.c_str())); 
        /* Perform the request, res will get the return code */ 
        res = curl_easy_perform(curl);
}

Hello World Service. 您好,世界服务。

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

Other web service. 其他网络服务。

    [WebMethod]
    public UpdateWorkFlowReply UpdateWorkFlow(UpdateWorkFlowRequest request)
    {
}

When i call the first service, everything is fine. 当我致电第一个服务时,一切都很好。 I then change to this line... 然后我转到这条线...

        curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:14523/Services/Service.asmx/UpdateWorkFlow");

This causes an error. 这会导致错误。

UpdateWorkFlow web service method name is not valid.

The thing is.... it definately definately is correct. 事情是……绝对是正确的。

Now, it leaps out at me that it might be due to the object that the web service expects. 现在,我突然意识到这可能是由于Web服务期望的对象。 The service itself does work as i have tested it with SoapUI. 该服务本身确实可以正常工作,因为我已经用SoapUI测试了它。 However, soapUI provides the request template. 但是,soapUI提供了请求模板。

How do i create the request? 如何创建请求? Simply an xml string? 只是一个xml字符串?

I changed this line but i still recieved the same error. 我更改了此行,但仍然收到相同的错误。 (???) The UpdateWorkFlowRequest is serializeable and allows null values. (???)UpdateWorkFlowRequest可序列化,并允许空值。

std::string content="<?xml version='1.0' encoding='utf-8'?><UpdateWorkFlowRequest></UpdateWorkFlowRequest>";

Regards 问候

Updated WebService Call 更新了WebService调用

[WebMethod]
public UpdateWorkFlowReply UpdateWorkFlow(string request)
{
}

With the request changed to.... 将请求更改为...。

std::string content="request=<request></request>";

Then set the content as normal. 然后正常设置内容。

curl_easy_setopt (curl, CURLOPT_POSTFIELDS, content);
curl_easy_setopt (curl, CURLOPT_POSTFIELDSIZE, strlen (content.c_str())); 

The error is now that the service cannot find request, the parameter it is expecting. 现在的错误是服务找不到请求,它是期望的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM