Link to home
Start Free TrialLog in
Avatar of JCC-UK
JCC-UKFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Serializing object from a Web Service

Hi all.....

I have an object: UserLoginResult which is defined within a namespace called BUSINESS OBJECTS.

I also have a webservice that references the BUSINESS OBJECTS namespace, and makes use of the UserLoginResultObject.

When serializing a UserLoginResult object from the webservice into another class within the BUSINESSOBJECTS namespace (UserBroker),
I get the problem of not being able to implicitly convert from biz.xxxxx.authentication.login.UserLoginResult to BusinessObjects.UserLoginResult

I'm confused about this as the Web service is referencing the same DLL and the same object...... am I missing something very straightforward here?
static public UserLoginResult login(String in_username, String in_password, String in_authentication_company)
        {
           UserLoginResult myresult = new UserLoginResult(); 
                  
           biz.xxxxxx.eyfswebservices.authentication myauth = new biz.xxxxxx.eyfswebservices.authentication();
 
          myresult =  myauth.Login(in_username, in_password, in_authentication_company);
 
// The line above complains about conversion
 
           return myresult;
        }

Open in new window

Avatar of jgordos
jgordos
Flag of United States of America image

I think it's a namespaces problem.

Your object that you're new-ing is

biz.xxxxxx.eyfswebservices.authentication

and it looks like that's not the namespace of your UserLoginResult object.

The objects, once serialized, generally depend on reconstructing themselves in the same class.. ie, that includes th name spaces.

you could, i bet, declare your local "myresult" object as

biz.xxxxxx.authentication.login.UserLoginResult myresult = new biz.xxxxxx.authentication.login.UserLoginResult();

and it should work fine.

One you have the object back into your address space, you can then copy the members to your UserLoginResult object via a copy constructor, or field by field, or whatever.

-john
Avatar of JCC-UK

ASKER

Thanks for the response!

I can get things working by doing the whole copying members method, but really wanted to avoid doing this - it seems long winded, especially as the object definitions are exactly the same apart from the namespaces that they're in.........

JC
static public UserLoginResult login(String in_username, String in_password, String in_authentication_company)
        {
           UserLoginResult myresult = new UserLoginResult();          
           biz.xxxxxxx.eyfswebservices.UserLoginResult myremoteresult = new biz.xxxxxxx.eyfswebservices.UserLoginResult();                  
           biz.xxxxxxx.eyfswebservices.authentication myauth = new biz.xxxxxxx.eyfswebservices.authentication();
           myremoteresult =  myauth.Login(in_username, in_password, in_authentication_company);
 
           myresult.Authentication_Company = myremoteresult.Authentication_Company;
 
           return myresult;
        }

Open in new window

Avatar of JCC-UK

ASKER

Updated code snipped with comments
namespace Business_Objects
{
    public static class UserBroker
 
 
    {
        /*     ADD USER     */
        static public Boolean add_user(User in_user)
        {
         return true;
        }
 
        static public UserLoginResult login(String in_username, String in_password, String in_authentication_company)
        {
          
            // Define two separate UserLoginResults in two different namespaces - one local (Business Objects)
            // The other in biz.appsoft.eyfswebservices.authentication
            
           UserLoginResult myresult = new UserLoginResult();        
           biz.appsoft.eyfswebservices.UserLoginResult myremoteresult = new biz.appsoft.eyfswebservices.UserLoginResult(); 
            
           // Create an instance of the webservice
 
           biz.appsoft.eyfswebservices.authentication myauth = new biz.appsoft.eyfswebservices.authentication();
 
           // Call the Login method of the web service and pass it into a UserLoginResult defined in the
           // biz.appsoft.eyfswebservices.authentication namespace
 
           myremoteresult =  myauth.Login(in_username, in_password, in_authentication_company);
 
           // Transfer the members into the UserLoginResult defined in the BUSINESS OBJECTS namespace from the
           // UserLoginResult that's defined in the biz.appsoft.eyfswebservices.authentication namespace
 
           myresult.Authentication_Company = myremoteresult.Authentication_Company;
 
           return myresult;
        }
 
 
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jgordos
jgordos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial