all groups > dotnet web services > october 2006 >
You're in the

dotnet web services

group:

Newbie Question - Best Practices


Newbie Question - Best Practices LW
10/24/2006 1:41:01 PM
dotnet web services:
Hi!
I have a question about the best way to proceed to write a web service. I am
new to this so would appreciate your comments.

I have the soap request and response. I have my DataSet so have all the
information to populate the response. My question is: How do I get from the
DataSet to the SOAP response? Do I generate my own XML schema? If yes, how?
Are there utilities to generate the xsd document from the soap response? Any
books or links that can answer some of these questions? I have been reading
the msdn forums and KB articles but am a bit confused as to the best way to
proceed.

Thanks,
Re: Newbie Question - Best Practices LW
10/24/2006 2:06:02 PM
Since Visual Studio cannot read my mind, how can I have it generate my
SOAP response in the correct format?

[quoted text, click to view]
Re: Newbie Question - Best Practices John Saunders
10/24/2006 5:57:33 PM
The answer to "how do I get from the DataSet to the response" is, "however
you want to".

The best way will not only depend on some abstract "best practices", but
also on you and your areas of expertise. For instance, if you're good with
XSL, you might want to use a stylesheet to transform the XML of the DataSet
into the correct form for the response. If not, you may simply be better off
copying the data from the DataSet into the proxy objects for the response:

// Proxy classes:

public class Employee
{
public string FirstName ...;
public string LastName ...;
public int ID ...;
}

public class Response
{
public int NumberOfEmployees;
public Employee[] Employees;
}

[WebService]
public class MyService : WebService
{
[WebMethod]
public Response MyMethod(Request request)
{
DataSet ds = GetDataSet(request);
DataTable employeesTable = ds.Tables["Employees"];
Response response = new Response();
response.NumberOfEmployees = employeesTable.Rows.Count;
response.Employees = new Employee[response.NumberOfEmployees];

for (int i=0; i<employeesTable.Rows.Count; i++)
{
DataRow dr = employeesTable.Rows[i];
Employee employee = new Employee();
employee.FirstName = (string) dr["FirstName"];
employee.LastName = (string) dr["LastName"];
employee.ID = (int) dr["ID"];
response.Employees[i] = employee;
}

return response;
}
}


Of course, if your requirements are not this simple, then your solution will
not be this simple, either.

John

Re: Newbie Question - Best Practices fallenidol
10/24/2006 9:46:23 PM
you simply need to create "web service" type project in visual studio. it
will generate all the necessary behind the scenes stuff to generate the soap
messages. you just and in your code as if it was a regular method.


[quoted text, click to view]

Re: Newbie Question - Best Practices LW
10/24/2006 10:55:01 PM
John,
Thank you for your response and your code example. It is exactly what I was
looking for. I have been reading about other options that were too
complicated for
me right now, and I was going around in circles.

Appreciate your help!

Cheers,
LW


[quoted text, click to view]
Re: Newbie Question - Best Practices fallenidol
10/25/2006 12:00:00 AM
you didnt say in your original post that you need it in a specific format


[quoted text, click to view]

AddThis Social Bookmark Button