gSoap - 服务调用返回 SOAP_OK,但返回未初始化的结构

发布于 2024-11-03 04:52:11 字数 2377 浏览 1 评论 0原文

这是一个取消引用空指针问题 - 在 ANSI C 和 ANSI C 中。 gSoap 域:

我正在使用以下公共WSDL

http://www.mobilefish.com/services/web_service/countries.php?wsdl

并使用soapUI 测试了其行为。< br> 我使用 wsdl2h 和soapcpp2 实用程序创建了仅客户端的 ANSI C 绑定。

问题:

在以前的 gsoap 项目中,客户端soap_call 函数中的结果结构(第五个参数)不需要初始化,除了类似的东西:

struct ns2__countryInfoByIanaResponse out, *pOut
pOut= &out;

在这个项目之前,这一直是足够的。
客户端soap_call看起来像这样:

soap_call_ns2__countryInfoByIana(&soap, NULL, NULL, pIn, pOut); /* SOAP 1.2 RPC return element...*/

这个项目的pIn被定义为char *,用两个字符IANA 代码,例如“us”或“nz”。此特定调用的返回结构 pOut 的形状如下:

struct ns2__countryInfoByIanaResponse
{
    struct ns1__CountryData *countryinfo;
}

ns1__CountryData 的形状如下:

struct ns1__CountryData
{
    char *ianacode; /* required element of type xsd:string */
    char *countryname;  /* required element of type xsd:string */
    float latitude; /* required element of type xsd:float */
    float longitude;    /* required element of type xsd:float */
};

因此,从我的应用程序对此函数的调用设置如下:

//declare response structure:
struct ns2__countryInfoByIanaResponse o, *pO;

void main(void)
{
   pO = &o;
   if(GetCountryInfo(buf, pO)==0)
   {
      pO->countryinfo->countryname; //Error Occurs Here...
   }                                
}

错误发生在 pO->countryinfo 作为空指针的取消引用

GetCountryInfo 在这里定义:

int DLL_EXPORT GetCountryInfo(char *pIn, struct ns2__countryInfoByIanaResponse *pOut)
{

    int status = 0;
    size_t len=2048;
    char buf[2048];

    if (soap_call_ns2__countryInfoByIana(&soap, NULL, NULL, pIn, pOut)== SOAP_OK)
    {
        status = 0;
    }
    else
    {
        //soap_print_fault(&soap, stderr);
        soap_sprint_fault(&soap, buf, len);
        MessagePopup("soap error", buf);
        status = 1;
    }
    return status;
}

使用类似输出结构形状(即结构)的其他 gSoap 项目包含包含 char *) 的结构在初始化时返回完全填充的结果,除了我上面显示的内容之外。

有什么想法吗?如果我可以提供更多详细信息,请告诉我。 谢谢。

This is a dereference of null pointer problem - in both the ANSI C & gSoap domains:

I am using the following public WSDL:

http://www.mobilefish.com/services/web_service/countries.php?wsdl

and have tested its behavior using soapUI.
I created client-side only ANSI C bindings using the wsdl2h and soapcpp2 utilities.

The problem:

In previous gsoap projects, results structures in the client soap_call functions (the fifth argument) required no initialization other than something like:

struct ns2__countryInfoByIanaResponse out, *pOut
pOut= &out;

this has always been sufficient until this project.
The client soap_call looks like this:

soap_call_ns2__countryInfoByIana(&soap, NULL, NULL, pIn, pOut); /* SOAP 1.2 RPC return element...*/

pIn for this project is defined as a char *, populated with a two character IANA code such as "us", or "nz". The return structure pOut for this particular call is shaped like this:

struct ns2__countryInfoByIanaResponse
{
    struct ns1__CountryData *countryinfo;
}

With ns1__CountryData shaped like this:

struct ns1__CountryData
{
    char *ianacode; /* required element of type xsd:string */
    char *countryname;  /* required element of type xsd:string */
    float latitude; /* required element of type xsd:float */
    float longitude;    /* required element of type xsd:float */
};

A call to this function from my application is therefore set up like this:

//declare response structure:
struct ns2__countryInfoByIanaResponse o, *pO;

void main(void)
{
   pO = &o;
   if(GetCountryInfo(buf, pO)==0)
   {
      pO->countryinfo->countryname; //Error Occurs Here...
   }                                
}

The error occurs at pO->countryinfo as a dereference of null pointer

GetCountryInfo is defined here:

int DLL_EXPORT GetCountryInfo(char *pIn, struct ns2__countryInfoByIanaResponse *pOut)
{

    int status = 0;
    size_t len=2048;
    char buf[2048];

    if (soap_call_ns2__countryInfoByIana(&soap, NULL, NULL, pIn, pOut)== SOAP_OK)
    {
        status = 0;
    }
    else
    {
        //soap_print_fault(&soap, stderr);
        soap_sprint_fault(&soap, buf, len);
        MessagePopup("soap error", buf);
        status = 1;
    }
    return status;
}

Other gSoap projects using similar output structure shapes (i.e. structures containing structures containing char *) returned fully populated results when initialized with nothing other than what I have shown above.

Any ideas? Please let me know if I can provide any further details.
Thanks.

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

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

发布评论

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

评论(1

秋千易 2024-11-10 04:52:11

在我看来,肥皂服务器有一个错误。来自countryInfoByIana 函数的示例肥皂响应如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <SOAP-ENV:countryInfoByIanaResponse>
      <return>
        <ianacode xsi:type="xsd:string">nz</ianacode>
        <countryname xsi:type="xsd:string">New Zealand</countryname>
        <latitude xsi:type="xsd:float">-40.900558</latitude>
        <longitude xsi:type="xsd:float">174.885971</longitude>
      </return>
    </SOAP-ENV:countryInfoByIanaResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

应该具有不同的命名空间。

这是 WSDL 的一部分,其中包含相同的(无效的)命名空间。

<operation name="countryInfoByIana">
  <soap:operation soapAction="http://schemas.xmlsoap.org/soap/envelope/#Countries#countryInfoByIana" />
  <input>
    <soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  </input>
  <output>
    <soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  </output>
</operation>

编辑:

关于你的问题为什么soapUI工作正常; SoapUI 可能不会像 gsoap 那样验证返回值。

我设法让程序在我的电脑上使用 gsoap 2.7 成功:

在soapClient.c 第56 行中,更改此行:

//soap_get_ns2__countryInfoByIanaResponse(soap, _param_1, "ns2:countryInfoByIanaResponse", "");
soap_get_ns2__countryInfoByIanaResponse(soap, _param_1, "SOAP-ENV:countryInfoByIanaResponse", "");

在soapC.c 第1470 行中,更改此行:

//if (soap_in_PointerTons1__CountryData(soap, "countryinfo", &a->countryinfo, "ns1:CountryData"))
if (soap_in_PointerTons1__CountryData(soap, "return", &a->countryinfo, "ns1:CountryData"))//return

但我认为您不应该以这种方式解决问题。不仅因为这两个文件都生成了,所以当您再次生成它时,您将丢失更改。

It looks to me like the soap server has a bug. An example soap response from the countryInfoByIana function looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <SOAP-ENV:countryInfoByIanaResponse>
      <return>
        <ianacode xsi:type="xsd:string">nz</ianacode>
        <countryname xsi:type="xsd:string">New Zealand</countryname>
        <latitude xsi:type="xsd:float">-40.900558</latitude>
        <longitude xsi:type="xsd:float">174.885971</longitude>
      </return>
    </SOAP-ENV:countryInfoByIanaResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<SOAP-ENV:countryInfoByIanaResponse> should have a different namespace.

Here is a part of the WSDL, which contains the same (invalid) namespace.

<operation name="countryInfoByIana">
  <soap:operation soapAction="http://schemas.xmlsoap.org/soap/envelope/#Countries#countryInfoByIana" />
  <input>
    <soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  </input>
  <output>
    <soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  </output>
</operation>

EDIT:

Regarding your question why soapUI works fine; soapUI probably does not validate the return value the same way gsoap is doing.

I managed to let the program succeed on my pc using gsoap 2.7:

In soapClient.c line 56, change this line:

//soap_get_ns2__countryInfoByIanaResponse(soap, _param_1, "ns2:countryInfoByIanaResponse", "");
soap_get_ns2__countryInfoByIanaResponse(soap, _param_1, "SOAP-ENV:countryInfoByIanaResponse", "");

In soapC.c line 1470, change this line:

//if (soap_in_PointerTons1__CountryData(soap, "countryinfo", &a->countryinfo, "ns1:CountryData"))
if (soap_in_PointerTons1__CountryData(soap, "return", &a->countryinfo, "ns1:CountryData"))//return

But I don't think you should solve problems this way. Not only because both files are generated, so you will lose your changes when you generate it again.

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