JCC-UK
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.l ogin.UserL oginResult to BusinessObjects.UserLoginR esult
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?
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.l
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;
}
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
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;
}
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;
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your object that you're new-ing is
biz.xxxxxx.eyfswebservices
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.
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