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 / March 2005

Tip: Looking for answers? Try searching our database.

Web Service Help for a Noob : Returning an XML String

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nastero - 29 Mar 2005 22:08 GMT
Hi All,

I'm trying to learn how to access data in a database via a webservice
and I'm experiencing a little bit of trouble at the moment.

Being a relative noobie to the entire .NET environment and languages,
I'm having difficulty pinpointing what the issue is and how I might go
about fixing it.

Also, when I actually did get it to return the XML String, this was the
return value :

 <?xml version="1.0" encoding="utf-8" ?>
 <string xmlns="http://localhost/CatfishService/"><dsPlayerList
xmlns="http://www.tempuri.org/dsPlayerList.xsd" /></string>

How do I change the xmlns from "http://www.tempuri.org" to localhost
(or whatever URL is applicable at the time)?

I'll include the code at the end of the message for your review.  I
only ask that, if you see the problem and know the answer, you relay
your advice in small words :).

====================== My Service Code ======================
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;

namespace CatfishService
{
  /// <summary>
  /// Summary description for Service1.
  /// </summary>
  ///
[WebService(Description="This is a Service Designed to Manage the
Catfish DB",Namespace="http://localhost/CatfishService/")]

  public class Service1 : System.Web.Services.WebService
  {
     public Service1()
     {
        //CODEGEN: This call is required by the ASP.NET Web Services
Designer
    InitializeComponent();
     }

     private SqlConnection SQLConnCatfishDB;
     private SqlDataAdapter sdaManageRoster;
     private SqlCommand sicAddToRoster;
     private SqlCommand scGetPlayerList;
     private CatfishService.dsPlayerList dsPlayerList;

     [WebMethod()]
     [return: XmlElement Namespace="http://localhost/CatfishService/",
ElementName="PlayerList")]

     public string GetPlayerList(int player_id, int is_active)
     {
        //SQLConnCatfishDB.Open(); (I commented this out because it
would not process anything after it, it would just open up a
webpage to nowhere).

        sdaManageRoster.SelectCommand.Prepare();
    sdaManageRoster.SelectCommand.Parameters["@player_id"].Value =
player_id;
        sdaManageRoster.SelectCommand.Parameters["@is_active"].Value =
is_active;

        //sdaManageRoster.Fill(dsPlayerList); (I commented this out
for the same reason above, not really certain why it does this).
    return dsPlayerList.GetXml();
     }

Thank in advance.

Cheers,

Daniel Hobert
Daniel Hobert - 29 Mar 2005 23:29 GMT
Hi again,

I was browsing through microsoft.public.dotnet.framework.webservices hoping
for an answer when I noticed a snippet of code in a semi-related thread that
I thought might help shed some light onto why I was unable to retrieve the
information necessary and why the page was incapable of being displayed.

I added the code below to my webMethod that is returning a string of XML
data and suddenly I was able to get to the heart of my issue.

So here goes.

  string xmlPlayerList;
  try
  {
   sdaManageRoster.SelectCommand.Connection.Open();
   sdaManageRoster.SelectCommand.Prepare();
   sdaManageRoster.SelectCommand.Parameters["@player_id"].Value =
player_id;
   sdaManageRoster.SelectCommand.Parameters["@is_active"].Value =
is_active;

   sdaManageRoster.Fill(dsPlayerList);
   xmlPlayerList = dsPlayerList.GetXml();
  }
  catch(Exception ex)
  {
   xmlPlayerList = ex.ToString();
  }

  sdaManageRoster.SelectCommand.Connection.Close();

  return xmlPlayerList;

 What this did for me was return the exact text of the exception I was
experiencing (but not seeing).  The gist of it is that the default user was
not able to execute a stored procedure in the master database and so I was
unable to open the Connection in the first place.  Once I put in the
necessary login info and made sure it was saved, my list of players was
successfully returned and displayed on the page.

This brings me to a new issue though, apparently by saving the login and
password I am exposing it in the code of the page and thus am leaving the
database open to be logged into by anyone, I suppose.  Does anyone know of a
better way to handle the opening of a connection where I won't be left
exposing the DB Login Information in such a way?

Thanks again in advance.

Cheers,

Daniel Hobert

> Hi All,
>
[quoted text clipped - 81 lines]
>
> Daniel Hobert
jerome - 31 Mar 2005 17:13 GMT
I'm sure there are more than one way to address this issue.  One
possibility would be to store your DB passwords and/or full connection
strings in a separate file that you can read at runtime.  The file
should be adequately protected so nobody can hack into to retrieve your
sensitive DB credentials.

> Hi again,
>
[quoted text clipped - 121 lines]
> > sdaManageRoster.SelectCommand.Parameters["@player_id"].Value =
> > player_id;

sdaManageRoster.SelectCommand.Parameters["@is_active"].Value =
> > is_active;
> >
[quoted text clipped - 8 lines]
> >
> > Daniel Hobert

Rate this thread:







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.