2012-01-07 79 views
0

我已經定義了一個名爲login的函數,它應該返回一個標記。令牌有一個安全ID是一個char *gSoap C++ - C#反序列化問題

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爲空。不知何故,它不會被反序列化。 另一方面,錯誤代碼,這是一個整數正確反序列化。

有什麼建議嗎?

回答

0

問題來自wsdl文件。看着gSOAP的文檔,我發現:

http://www.cs.fsu.edu/~engelen/soapfaq.html

<x:foo xmlns:x="urn:foo" xmlns="urn:bar"> 
    <bar></bar> 
</x:foo> 

在最後一個例子杆構件屬於「甕:酒吧」命名空間,因爲默認的命名空間是「甕:酒吧」。使用Visual Studio .NET 2003 WSDL導入,當響應元素在第二個命名空間中包含結構類型的元素時,我們無法成功地從多命名空間情況反序列化數據。在.NET方面,結構的各個成員被忽略,直到定義了元素表單默認的「限定」爲止。

因此,設置attributeFormDefault =「qualified」和elementFormDefault =「qualified」固定了序列化問題。