سؤال

I have this code to use lib curl to call my asmx webservice. It works for my HelloWorld service. The asmx webservice is written in Visual Studio 2012. I am attempting to make a restful interface, not 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. The service itself does work as i have tested it with SoapUI. However, soapUI provides the request template.

How do i create the request? Simply an xml string?

I changed this line but i still recieved the same error. (???) The UpdateWorkFlowRequest is serializeable and allows null values.

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

Regards

هل كانت مفيدة؟

المحلول

Updated WebService Call

[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 مع الإسناد
لا تنتمي إلى StackOverflow
scroll top