Search code examples
c++xmlvisual-c++gsoap

making a web services query using gSoap with query arguments


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++ / 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!


Solution

  • 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.