开发者

making a web services query using gSoap with query arguments

开发者 https://www.devze.com 2023-01-09 03:30 出处:网络
I\'m attempting to convert a soap query written for C# into a gSoap query in Visual C++. The C# query adds an XML node\'s to the query call, in order to pass parameters to the query:

I'm attempting to convert a soap query written for C# into a gSoap query in Visual C++.

The C# query adds an XML node's to the query call, in order to pass parameters to the query:

XmlNode queryOpts = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
queryOpts.InnerXml = "<DateInUtc>TRUE</DateInUtc>";

Here's the C# query, passing various args (some args are specified as XmlNode objects)

XmlNode nodeListItems = listService.GetListItems("Announcements", null, query, viewFields, null, queryOpts, null);

The C开发者_JS百科++ / gSoap query allows me to pass a query and response object:

listService.__ns10__GetListItems(&announcementQuery, &announcementResponse)

The query object has various properties that can be set that relate to the arguments in the C# call:

announcementQuery.listName  
announcementQuery.query   
announcementQuery.queryOptions 
announcementQuery.viewFields 

The first argument there is a string, no problem.

The query, queryOptions and viewFields are a bit confusing.

"query" is a class of type _ns2__GetListItems_query, and it has the following functions & members:

soap_default()
soap_get()
soap_in()
soap_out()
soap_put()
soap_serialize()
soap_type()
__any
__mixed

for query, queryOptions and viewFields, I'd simply like to specify an xml formatted string, like the C# code does, but I'm not sure how this is done.

Can someone cast some experience on this?

thanks!


I'm assuming you've already discovered the answer to this, but I'll post some notes for posterity.

Here's a simple C++ demo for sending and XML doc to a ASP.NET web method.

int _tmain(int argc, _TCHAR* argv[])
{
    Service1SoapProxy proxy;

    _WebServiceNS1__HelloWorld helloWorld;
    _WebServiceNS1__HelloWorld_xml xml;
    _WebServiceNS1__HelloWorldResponse response;

    xml.__any = "<doc><x>hi</x></doc>";
    helloWorld.xml = &xml;

    int result = proxy.HelloWorld(&helloWorld, &response);
    fprintf(stdout, "result: %i\n", result);

    switch(result)
    {
        case SOAP_OK:
            fprintf(stdout, "Response: %s\n", response.HelloWorldResult);
            break;
        default:
            break;
    }

    return 0;
}

Here's the trivial web method in the .NET service:

[WebMethod]
public string HelloWorld(XmlNode xml)
{
    return string.Format("Your XML: {0}", xml.OuterXml);
}

If everything works, you'll see "Response: hi" on your console.

0

精彩评论

暂无评论...
验证码 换一张
取 消