Gsoap,从旧版本迁移- XML响应名称和结构已更改

gsoap, migrate from old version - xml response name and structure has changed

本文关键字:结构 响应 XML 版本 迁移 Gsoap      更新时间:2023-10-16

我们有一个cgi,我必须从旧的gsoap版本迁移到gsoap 2.8.14。不幸的是,人们的反应并不相同。我添加了//gsoap的模式形式:不合格到header,但这还不足以摆脱所有ns前缀。第二个可能也是最主要的问题是响应命名。在loginResponse中,进一步的LoginResult现在被称为result和packet。

旧cgi的响应:

<LoginResult>
    <successful>true</successful>
    <token>example</token>
</LoginResult>

new cgi

响应
<ns:loginResponse>
    <result>
        <successful>true</successful>
        <token>example</token>
    </result>
</ns:loginResponse>

我使用soapcpp2 -e -S auth.h构建存根

auth.h是这样的:

//gsoap ns service name: auth
//gsoap ns service style: rpc
//gsoap ns service encoding: encoded
//gsoap ns service port: http://domain.xy/cgi-bin/auth.cgi
//gsoap ns service namespace: urn:auth
//gsoap ns schema form: unqualified
typedef std::string xsd__string;
// array of strings containing all tags allowed for a specific user
class TagsArray
{
public:
    xsd__string *__ptr;
    int __size;
    TagsArray();
};
// getTags.... result struct
class TagsResult
{
public:
    bool successful;
    xsd__string errorMessage;
    TagsArray tags;
    TagsResult();
};
// login result struct
class LoginResult
{
public:
    bool successful;
    xsd__string token;  // also used as error message if successful == false
    LoginResult();
};
// verify result struct
class VerifyResult
{
public:
    bool successful;
    xsd__string newToken;   // also used as error message if successful == false
    VerifyResult();
};
// contains a valid auth method for a specific realm
class ns__AuthMethod
{
public:
    int id;
    xsd__string description;
};
// array of all allowed authmethods for a specific realm
class AuthMethodArray
{
public:
    ns__AuthMethod *__ptr;
    int __size;
};
// a login parameter, usually username, pin, token
class ns__LoginParameter
{
    xsd__string param;
    xsd__string value;
};
// array of all submitted login parameters, depending on the authmethod that is used
class LoginParameterArray
{
public:        
    ns__LoginParameter *__ptr;
    int __size;
};

// retrieve all possible authmethods for a specific realm
int ns__getAuthMethods(xsd__string realm, xsd__string user, AuthMethodArray &result);
// login and retrieve a valid token if succeeded
int ns__login(xsd__string realm, int authmethod, LoginParameterArray params, LoginResult &result);
// verify a existing token
int ns__verifyToken(xsd__string realm, xsd__string token, VerifyResult &result);

任何想法?谢谢。

----------------- 05.04.2013 ---------------谢谢你,戴夫!

更改完成:

  • ns__前缀由Dave建议
  • 删除构造函数
  • set bool默认值为false

    //登录结果结构类ns_ LoginResult{公众:Bool成功= false;xsd _string令牌;//如果成功也用作错误消息== false

    };

结果现在看起来像这样:

 <ns:LoginResult>
     <successful>true</successful>
     <token>example</token>
  </ns:LoginResult>
int ns__login(xsd__string realm, int authmethod, LoginParameterArray params, ns__LoginResult &result);

ns:前缀被所有客户端处理(php, .net, c++(qt))没有问题。

您需要在auth.h中更改LoginResult:

// login result struct
class ns__LoginResult
{
public:
    bool successful;
    xsd__string token;  // also used as error message if successful == false
    LoginResult();
};

同时修改ns_login()方法如下:

int ns__login(xsd__string realm, int authmethod, LoginParameterArray params, ns__LoginResult &result);

生成的响应如下所示:

  <ns:LoginResult>
   <successful>false</successful>
   <token></token>
  </ns:LoginResult>

希望LoginResult移到"ns"命名空间不会对您造成太大的问题。