[英]gSoap C++ - C# deserialization issue
我定義了一個名為login的函數,該函數應返回令牌。 令牌的安全性ID為char *
SOAP_FMAC5 int SOAP_FMAC6 __afas__login(struct soap* env, afas__Login *afas__login, afas__LoginResponse *afas__loginResponse)
{
int ret = ServiceApp::GetServiceApp()->GetServiceImpl()->login(afas__login->user, afas__login->password);
afas__loginResponse->error = soap_new_afas__Error(env, -1);
afas__loginResponse->af__token = soap_new_af__Token(env, -1);
if (ret == sERROR)
{
afas__loginResponse->error->code = afas__ErrorCode__NOTLOGGEDIN;
}
else
{
afas__loginResponse->error->code = afas__ErrorCode__SUCCESS;
afas__loginResponse->af__token->sessionId = soap_strdup(env, soap_int2s(env, ret));
afas__loginResponse->af__token->securityId = soap_strdup(env, afas__login->password);
afas__loginResponse->af__token->userName = soap_strdup(env, afas__login->user);
}
return SOAP_OK;
}
在客戶端,我對此有一個電話:
AuthenticationServiceClient a = new AuthenticationServiceClient();
Login login = new Login();
login.user = "test";
login.password = "test";
LoginResponse lr = a.login(login);
string securityId = lr.token.sessionId
問題是secuirtyId為null。 不知何故它不會反序列化。 另一方面,錯誤代碼(它是整數)已正確反序列化。
有什么建議么 ?
問題來自wsdl文件。 查看我發現的gSOAP文檔:
http://www.cs.fsu.edu/~engelen/soapfaq.html
<x:foo xmlns:x="urn:foo" xmlns="urn:bar">
<bar></bar>
</x:foo>
在最后一個示例中,bar元素屬於“ urn:bar”名稱空間,因為默認名稱空間是“ urn:bar”。 使用Visual Studio .NET 2003 WSDL導入,當響應元素在第二個命名空間中包含結構類型的元素時,我們無法從多命名空間情況下成功反序列化數據。 在.NET端忽略該結構的各個成員,直到定義了默認“ qualified”形式的元素。
因此,設置attributeFormDefault =“ qualified”和elementFormDefault =“ qualified”可以解決序列化問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.