xml serialization and de-serialization of generic list in C#.net
I am preparing a code structure like the following;
WCF service - all business logic can implement here. All service methods can takes input arguments as string(XML data) and can return string (XML data) or int.
Client Website - ASP>NET web site with entity layer and business logic layer(BAL layer).
Flow is like this:
client Website --->BAL--> (WCF service----> DAL Layer---->Database) BAL layer consume wcf service
For this purpose, in BAL layer, I want to create a list of entity class and do XML serialization(list to XML format) and pass it to a WCF service methods.other side in WCF service method de-serialization(XML to list).
开发者_开发知识库How do I do this in ASP.NET and WCF?
You don't do that. This seems to be a common misunderstanding for new users of WCF.
You define your DataContracts which contains your data, pass them to your WCF service, and it takes care of serializing/deserializing them.
You do not serialize them to XML before passing them through the service.
WCF will automatically serialize a list for you, but the default collection type it is deserialized to on the client side is an array.
You can change this default collection to a list (or linked list, or anything else available) by right clicking on your service reference in the project for your client application, selecting "Configure Service Reference...", and selecting System.Collections.Generic.List from the collection type drop down menu.
If you are sending a list from a client to the WCF service, it is sufficient to define you Service method's parameter as a list (if it contains simple .NET types), otherwise you need to define a special data contract as per the other answer.
精彩评论