|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to pass global parms to web service???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? -- JP ..NET Software Developer 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 ); } } Show quote "JP" <J*@discussions.microsoft.com> wrote in message news:02B74A8B-1D82-4F46-AA17-C24F056E6883@microsoft.com... >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? > > > -- > JP > .NET Software Developer |
|||||||||||||||||||||||