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 / .NET Framework / New Users / February 2007

Tip: Looking for answers? Try searching our database.

How to pass global parms to web service???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JP - 08 Feb 2007 17:24 GMT
I have a web service with several methods in it. When the user creates an
instance of this WS, I want to pass parameters to the instance:

localhost.WSdemographics myClass= new localhost.WSdemographics(string
Username, string Password);

Once the user creates this instance, then they can use the actual methods in
the service:

DataSet my DS = myClass.GetNames(int RecordGroup);

But when I go to create the instance of 'myClass' I do not get the 2
parameters in the intellisense. It wont even build, b/c it says the class
does not take parms, yet its defiend as

public class WSdemographics : System.Web.Services.WebService
{
   public WSdemographics(stringUserName,string Password)
   {
    ...
   }
...//WebMethods
...
}
I dont want to have to pass the userName and Password to every moethod in
the service, just at the point its reference. Why cant this be done?

Signature

JP
.NET Software Developer

Ashot Geodakov - 09 Feb 2007 19:17 GMT
Hi JP,

Why not to define the web service like this:

public class WebServiceTest : System.Web.Services.WebService
{
   public WebServiceTest()
   {
   }

   [WebMethod]
   public void SetCredentials( string u, string p )
   {
       Context.Cache["UserName"] = u;
       Context.Cache["Password"] = p;
   }

   [WebMethod]
   public string GetCredentials()
   {
       return Context.Cache["UserName"] + ", " + Context.Cache["Password"];
   }
}

Then you don't have to pass these username and password to every method.
You can call it in your client app like this:

   static class Program
   {
       /// <summary>
       /// The main entry point for the application.
       /// </summary>
       [STAThread]
       static void Main()
       {
           localhost.WebServiceTest test = new
WindowsApplication1.localhost.WebServiceTest();
           test.SetCredentials( "username", "password" );
           string str = test.GetCredentials();
           Console.WriteLine( str );
       }
   }

>I have a web service with several methods in it. When the user creates an
> instance of this WS, I want to pass parameters to the instance:
[quoted text clipped - 23 lines]
> I dont want to have to pass the userName and Password to every moethod in
> the service, just at the point its reference. Why cant this be done?

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.