webservice

P

Peter K

Hi

I have an existing web-application, with some "backend" code which fetches
data from a database (and is used on a website).
Now I need to write a webservice which calls some of these backend
functions, and exposes data to clients.

But the backend code is written using interfaces, so I don't actually get
concrete types returned - so I can't return them via a webservice (as far as
I know).

For example, there is a backend function in a UserDataAccess class, like:
IUser GetUser(long id);

If I want to expose this via a webservice, do I need to write my own
concrete "User" object, which I instantiate in my webservice based on the
IUser instance I get from the backend, before returning it to the client?

Sometimes, I am getting lists/arrays from the backend:
IUser[] GetUserList();

So here, do I need to loop through the entire list, converting each object
to my own "concrete type", before returning?

Is there a better way?

Thanks,
Peter
 
M

Mr. Arnold

Peter K said:
Hi

I have an existing web-application, with some "backend" code which fetches
data from a database (and is used on a website).
Now I need to write a webservice which calls some of these backend
functions, and exposes data to clients.

But the backend code is written using interfaces, so I don't actually get
concrete types returned - so I can't return them via a webservice (as far
as I know).

For example, there is a backend function in a UserDataAccess class, like:
IUser GetUser(long id);

If I want to expose this via a webservice, do I need to write my own
concrete "User" object, which I instantiate in my webservice based on the
IUser instance I get from the backend, before returning it to the client?

Sometimes, I am getting lists/arrays from the backend:
IUser[] GetUserList();

So here, do I need to loop through the entire list, converting each object
to my own "concrete type", before returning?

Is there a better way?

Use a WCF Web service that uses implicit serialized data contract objects.

The WCF Web service interface IService would have this.

[Operational Contract]
User GetUser(long id)


The Service would have this in it that IService points to.

public User GetUser(long id)
{
var dal = new DAL();
return dal.GetUser(long id)
}

IUser would become List<User> with Operational Contract for geting a
List<User> and its Service method.

The class which must be decorated with the attributes to make it an implicit
serialized data contract class to WCF.

The DAL will instanciate a new User and return it back to the BLL's method
that called WCF Web service's GetUser(22)



[Serializable]

[DataContractAttribute(IsReference=true)]

public class Shippers

{

private List<BrokenRule> _brokenrules = new List<BrokenRule>();

private List<Duane>_duanes = new List<Duane>();

private Int32 _shipperid;

private string _companyname;

private string _phone;


#region public properties


[DataMemberAttribute]

public List<BrokenRule> BrokenRules

{

get { return _brokenrules; }

set { _brokenrules = value; }

}

[DataMemberAttribute]

public List<Duane> Duanes

{

get { return _duanes; }

set { _duanes = value; }

}


[DataMemberAttribute]

public Int32 ShipperID

{

get { return _shipperid; }

set

{

if (_shipperid != value)

{

_shipperid = value;

}

}

}

[DataMemberAttribute]

public string CompanyName

{

get { return _companyname; }

set

{

if (value == null) value = string.Empty;

if (_companyname != value)

{

_companyname = value;

}

}

}

[DataMemberAttribute]

public string Phone

{

get { return _phone; }

set

{

if (value == null) value = string.Empty;

if (_phone != value)

{

_phone = value;

}

}

}

#endregion




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4180 (20090623) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top