mail2som

Guys can someone advise on this ..


1] My datasource is an array provided by an external component

2] I'll be formatting this array and exposing it to the enterprise as an asp.net 2.0 webservice
3] The client consuming this webservice is also a .net 2.0 application, maybe after a year there may a java application which would also want to consume this webservice.

My doubts:

1] I can format the array into either business entities or dataset.
Should I return custom entities or dataset considering :
(a)I want performance and (b)The client is also a .net application.

2] Will the custom entities be lightweight on the network as compared to the dataset

3] Will there be more overhead on the server in creating custom entities or datsets from the array

later on when the Java client comes into the picture I can serialize the dataset/custom entity to the standard Xml format.



Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

John Saunders

Your web service shouldn't do any formatting at all. Just return the data in a simple, portable manner. Let the consumer create either business entities or datasets, or whatever they like.

In particular, a web service can't really return a "classic" business entity, since those have behavior as well as data.






Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

mail2som

Thanks for reply..!!

As you mentioned "data in a simple, portable manner" , just wanted to know what format should this be

I'll explain myself better:

- I get a customer's line items in an array from a datasource.

- How do I return this customer info from my webmethod what shoud be the "return datatype" of my webmethod

-(a)Should I just return an array containing a header array and a line item array

-(b)Return as a dataset containing 2 datatables one for the header and one for the line items

-(c)A custom class containing the header items as property and the line items in a custom collection

Which format would you suggest from a,b and c
(I have understood that the client will then use any one of these formats returned by the webservice to create his own busines entities)
- I'm inclined toward using option (b) or (c)

regarding option (c) will I have to also have to give a reference to this "custom class" at the client side





Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

John Saunders

struct LineItem

{

public int Id {}

// ...

}

struct Customer

{

public string FirstName {}

public LineItem[] LineItems {}

}






Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

mail2som

Thats very helpful...

Just have a query regarding the choice of structs over classes:

1] I will be creating an instance of line item , there may be around 100 line items and the line item looks like this :

public struct lineitem

{

private int _item1;

private int _item2;

public int item1

{get

{return _item1;}

set {_item1 = value;}

}

public int item2

{get

{ return _item2;}

set {_item2 = value; }

}

}

2] There will be multiple line items so I will be using an array to hold all the multiple line items.

(a)Will there be an issue of boxing/unboxing while doing this will we lose the advantage of value type when boxing occurs

(b)If I use a class instead of struct for line item , I will use a custom collection by "using System.Collections" and there will be no boxing/unboxing involved.

Do you think we should go for class within customcollection as container or struct within an array as container

or should I simply return a string from the webservice containing the XML e.g

"<customer><header></header><lineitems><item>1</item><item>2</item></lineitems></customer>" ...





Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

John Saunders

First, you should almost never return a string as XML.

Read that sentence again. "string" as "XML". The two words are spelled differently, which is a hint that they are different. So, please don't act like they're the same.

[This is more for other readers than for you]

There won't be any boxing going on, so don't worry about it. Just use that array, or List<LineItem> to hold your line items. You can even return a List<LineItem>, and the client will see it as an array of LineItem.






Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

mail2som

Thanks again,

Now I have used generics to create a List<clientlineitem> to hold the line items.

My webservice is now returning the Struct "Customer" with header and line items.

<
xml version="1.0" encoding="utf-8" >

<Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<header1>xyz</header1>
<LineItems>
<clientlineitem />
<clientlineitem />
<clientlineitem />
<clientlineitem />
</LineItems>
</Customer>
I have a few queries at this stage :
(a) Will I have to provide a reference of the struct class to the .net client also as the return type of the webservice is "Customer" is there any way around this
(b)Will this be Platform independant since Im now having to give the refrence to the .Net struct in the client code which could be a Java application later on




Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

John Saunders

This is completely portable. Note that even a .NET client couldn't find your struct, since the full type name of the struct isn't serialized. The client will see this as a struct with a header and an array of clientlineitem structs.






Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

mail2som

Ok, thanks

Im a bit confused now :


Wouldn't the following xml be easier to parse

<customer>

<header>

</header>
<lineItems>

<item>1</item>

<item>2</item>

</lineitems>

</customer>

As compared to :

Receiving a "Customer" struct from the webservice, which the client will not be able to figure out how to parse since he has no reference to the original Customer struct, and getting the values wont be as simple as accessing the properties e.g "Customer.header", "customer.lineitems" etc

How will I extract the values as I dont have a reference to the Customer struct

How does the client use this unknown format





Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

John Saunders

Please just try it.




Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

mail2som

I gave a web reference to the webservice and got a proxy.

When I instantiate the webservice and call the method, the return type is "customer"


webserviceObj = new WebService1();

webserviceObj.GetCustomer("123");

I need some help on this..

what do I do with this "customer" returned from the webservice How do I parse it now

Do I give a reference to the "customer" struct in my client side code
If yes then will it work when I use a Java client

I need help on what needs to be done with this returned type.





Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

John Saunders

Try this. Assign the returned object to a local variable. You should be able to see the type of variable to use by hovering the mouse over the word "GetCustomer". If your web reference is called "reference", then the type is probably "reference.customer":

Code Block

reference.WebService1 webServiceObj = new WebService1();

reference.customer cust = webServiceObj.GetCustomer("123");

Now, single-click the word "customer" in "reference.customer". Then right-click and choose "Goto Definition". This should take you to the definition of the proxy class "reference.customer", where you can see exactly what your client will have to work with.




Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

mail2som

Thanks a lot again !!very useful.

I have managed to bind the header info of the customer to my client.

I'm currently working on getting hold of the individual lineitem withing the lineitem collection, however it seems the public properties which I had defined for the lineitem is not being exposed.

Code Block

customerWebservice.WebService1 serviceObj;

customerWebservice.Customer customerObj;

customerWebservice.lineitem[] lineItemCollectionObj;

customerWebservice.lineitem lineItemObj;

serviceObj = new WebService1();

customerObj = serviceObj.GetCustomer("123"); //header info

lineItemCollectionObj = customerObj.LineItemList; //get the entire lineitem Collection

lineItemObj = lineItemCollectionObj[0]; //get the 1st linetem from the collection

lineItemObj.property1()//unable to access the public property1 of the line item

lineItemObj.property2()//unable to access the public property2 of the line item

(I've been marking your posts as "helpful" but still the "number of helpful post" displays as zero at the top of the page... anything Im doing wrong )





Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

John Saunders

Are the properties public and read/write Even if you don't need the setter, you have to add a setter in order for the property to be serialized.






Re: ASMX Web Services and XML Serialization Should webservice return custom entity or dataset (Consider performance)

mail2som

Great !! eveything works perfect !!
I did not have any setters for the property...

I added the setters and I'm able to access the properties correctly.


Only 1 last question ... Will the java clients be able to use this or this webservice is only ".Net specific" clients only as the struct was in .Net