2

これは、ヌルポインタの問題の逆参照です-ANSICドメインとgSoapドメインの両方で:

私は次のパブリックWSDLを使用しています:

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

そしてsoapUIを使用してその動作をテストしました。
wsdl2hおよびsoapcpp2ユーティリティを使用して、クライアント側のみのANSICバインディングを作成しました。

問題:

以前のgsoapプロジェクトでは、クライアントのsoap_call関数(5番目の引数)の結果構造には、次のようなもの以外の初期化は必要ありませんでした。

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このプロジェクトでは、「us」や「nz」などchar *の2文字のIANAコードが入力されたとして定義されます。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...
   }                                
}

エラーは、nullポインタ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 *を含む構造を含む構造)は、上記で示したもの以外で初期化すると、完全に入力された結果を返しました。

何か案は?詳細をお知らせいただければお知らせください。ありがとう。

4

1 に答える 1

1

私には、soapサーバーにバグがあるように見えます。countryInfoByIana関数からのsoap応答の例は、次のようになります。

<?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>別の名前空間が必要です。

これは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を使用して、PCでプログラムを成功させることができました。

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

しかし、私はあなたがこの方法で問題を解決するべきではないと思います。両方のファイルが生成されるだけでなく、再度生成すると変更が失われます。

于 2011-04-22T23:02:42.807 に答える