For Programmers: Free Programming Magazines  


Home > Archive > Microsoft Webservices > May 2005 > Passing BLL objects between webApp and WebService









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Passing BLL objects between webApp and WebService
MattC

2005-05-23, 8:59 am

Just trying to see if this is possible.

I have created a BLL test project with a single class called Person, that
just exposes a property called Name which is set on construction.

I then created a webservice project that added the BLL assembly and exposes
a WebMethod that returns a newly constructed Person.

Finally I have created a WebApp that adds both the BLL and Webservice as
references. I tried to see if I could use the Person object across the
boundary.

The webform looks like this:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using WebApp.WS; //<--my webservice namepace
using BLL;

namespace WebApp
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
private TestService personHolder;

private void Page_Load(object sender, System.EventArgs e)
{
personHolder = new TestService();

BLL.Person tester = (BLL.Person)personHolder.GetPerson();

Label1.Text = tester.Name;
}
}

The error I get is Cannot convert type 'WebApp.WS.Person' to 'BLL.Person'

They are the same object from a copy of the same DLL?

TIA

MattC




Henrik Gøttig

2005-05-31, 9:12 am

>
> They are the same object from a copy of the same DLL?
>

No way - they are not. They might look similar, but they are not the
same. From the info that you provide, they reside in two different
namespaces "WebApp.WS.Person" and "BLL.Person", that alone makes them
different classes.

You could take different paths here, depending on what version of .NET /
VS you have. For VS 2005 / .NET 2.0 I would definately recommend to use
the /sharetypes swtich with WSDL. Take a look at it on MSDN.

If you not on .NET 2.0 you could make your classes implement the same
interface - that way you can gain type compability between them.
There are other ways, too. But the main task is one of:

1)
Actually make the class the same - on both server and client

2)
Make the two classes - one on client and one on server - type compatible
in some way.

Regards

Henrik
websolver.blogspot.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com