• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

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

0
JCC-UK
Asked:
JCC-UK
  • 2
  • 2
1 Solution
 
jgordosCommented:
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
0
 
JCC-UKAuthor Commented:
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

0
 
JCC-UKAuthor Commented:
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

0
 
jgordosCommented:
Yeah, you and I both know the objects are the same, but there's no way for the compiler to know this... it uses the symbol names.

Create a constructor in the local namespace object that takes as an argument the longer namespaced object... and in that constructor, copy the fields.

It'll clean up your higher level code, and you can get over this namespace problem.

Something like:

public UserLoginResult ( biz.xxxxxx.authentication.login.UserLoginResult _longName )
{
       this.A = _longName.A;
      this.B = _longName.B;

   // etc...


}


-john

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now