Search code examples
c#c++web-servicesgsoap

gSoap C++ - C# deserialization issue


I have defined a function called login that should return a token. The token has a security id which is a 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;

}

On the client side I have a call to this :

AuthenticationServiceClient a = new AuthenticationServiceClient();
Login login = new Login();
login.user = "test";
login.password = "test";
LoginResponse lr = a.login(login);

string securityId = lr.token.sessionId

The problem is that secuirtyId is null. Somehow it doesn't get deserialized. On the other hand, the error Code, which is an integer is deserialized correctly.

Any suggestions ?


Solution

  • The problem comes from the wsdl file. Looking at gSOAP docs I found:

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

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

    In the last example the bar element belongs to the "urn:bar" namespace, because the default namespace is "urn:bar". With Visual Studio .NET 2003 WSDL import, we could not successfully deserialize data from a multi-namespace situation when a response element contains an element of struct type in a second namespace. The individual members of the struct were ignored on the .NET side until the element form default 'qualified' was defined.

    So setting attributeFormDefault="qualified" and elementFormDefault="qualified" fixed the serialization issue.