gSoap - 服务调用返回 SOAP_OK,但返回未初始化的结构
这是一个取消引用空指针问题 - 在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,肥皂服务器有一个错误。来自countryInfoByIana 函数的示例肥皂响应如下所示:
应该具有不同的命名空间。这是 WSDL 的一部分,其中包含相同的(无效的)命名空间。
编辑:
关于你的问题为什么soapUI工作正常; SoapUI 可能不会像 gsoap 那样验证返回值。
我设法让程序在我的电脑上使用 gsoap 2.7 成功:
在soapClient.c 第56 行中,更改此行:
在soapC.c 第1470 行中,更改此行:
但我认为您不应该以这种方式解决问题。不仅因为这两个文件都生成了,所以当您再次生成它时,您将丢失更改。
It looks to me like the soap server has a bug. An example soap response from the countryInfoByIana function looks like this:
<SOAP-ENV:countryInfoByIanaResponse>
should have a different namespace.Here is a part of the WSDL, which contains the same (invalid) namespace.
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:
In soapC.c line 1470, change this line:
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.