LINQ to XML in a WCF Service

Hello Experts,
I have to create a wcf service and inside the service i have to do some basic operations on a xml file using LINQ to XML. I have to host the service in IIS 7.0 and consume it.
As part of the LINQ to XML I have to do the following tasks :
1. find all the questions in all the tests that answers are no
2. modify the question and answer of Test id="test2"
3. save the xml to db and then extract values such as question and answers
4. save the test and questions into a normalized db with tables such as Test and Question based on given xml

You can have a method on the Test class called 'SaveTest()'. This would save the individual test to your database in a normalized format and a similar method on the Question class to save the questions and answers to the database table.

What exactly do you want to be exposed as a service? Each of the tasks you've mentioned above?

So I'm assuming the input for your service method is the xml posted above. If that's the case, here's how I would go about building that.

I would keep the NestedXml() method as a private method that returns List<Test> based on the xml input. I would change its name though to something appropriate.

I'll have a service method called 'ParseTests' that takes in the xml as a parameter. Here's the pseudocode:

public void ParseTests(string xmlInput)
{
List<Test> tests = NestedXml(xmlInput);
// this is for the second requirement
// I'm not sure what you want in this method
// so you can create/use it appropriately
ModifyTestValues(ref tests);
// Persist the tests to a database
SaveTests(tests);
}

This does not make sense. I did give solution to read your XML and provided direction as to how to meet your requirements. 'Solved my problem' is not a good enough explanation for closing this without assigning points.

LINQ stands for LANGUAGE INTEGRATED QUERY. Think of it as a 'select' statement that you run on your database table. This statement does not modify the table values right? So LINQ is not to be used for modifying your collection... only for querying.

You're better off using a for loop on the 'tests' instance and change it where required.

Arun

0

Featured Post

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…

Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…

Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…