Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / October 2006

Tip: Looking for answers? Try searching our database.

Newbie Question - Best Practices

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LW - 24 Oct 2006 21:41 GMT
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,
LW
fallenidol - 24 Oct 2006 21:46 GMT
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.

> Hi!
> I have a question about the best way to proceed to write a web service. I
[quoted text clipped - 16 lines]
> Thanks,
> LW
LW - 24 Oct 2006 22:06 GMT
Since Visual Studio cannot read my mind, how can I have it generate my
SOAP response in the correct format?

> 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
[quoted text clipped - 20 lines]
> > Thanks,
> > LW
John Saunders - 24 Oct 2006 22:57 GMT
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
LW - 25 Oct 2006 06:55 GMT
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

> The answer to "how do I get from the DataSet to the response" is, "however
> you want to".
[quoted text clipped - 50 lines]
>
> John
fallenidol - 25 Oct 2006 07:54 GMT
you didnt say in your original post that you need it in a specific format

> Since Visual Studio cannot read my mind, how can I have it generate my
> SOAP response in the correct format?
[quoted text clipped - 27 lines]
>> > Thanks,
>> > LW

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.