使用带有查询参数的 gSoap 进行 Web 服务查询

发布于 2024-09-12 03:07:28 字数 1166 浏览 10 评论 0原文

我正在尝试将为 C# 编写的soap 查询转换为Visual C++ 中的gSoap 查询。

C# 查询将 XML 节点添加到查询调用中,以便将参数传递给查询:

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

这是 C# 查询,传递各种参数(某些参数被指定为 XmlNode 对象)

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

C++ / gSoap 查询允许我传递查询和响应对象:

listService.__ns10__GetListItems(&announcementQuery, &announcementResponse)

查询对象具有可以设置的与 C# 调用中的参数相关的各种属性:

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

第一个参数是一个字符串,没问题。

query、queryOptions 和 viewFields 有点令人困惑。

“query”是_ns2__GetListItems_query类型的类,它具有以下功能&成员:

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

对于查询、queryOptions 和 viewFields,我只想指定一个 xml 格式的字符串,就像 C# 代码所做的那样,但我不确定这是如何完成的。

有人可以就此提供一些经验吗?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み零 2024-09-19 03:07:28

我假设您已经找到了答案,但我会为后代发布一些注释。

下面是一个简单的 C++ 演示,用于将 XML 文档发送到 ASP.NET Web 方法。

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;
}

以下是 .NET 服务中的简单 Web 方法:

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

如果一切正常,您将在控制台上看到“Response: hi”。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文