To test your web service why don't you add a separate project. I mean in the
same solution you add another project may of a windows application type. Most
probably you will not have the null refrence problem.
"Pablo Cibraro [MVP]" wrote:
> Hi,
>
> Is the generated proxy using the same xml namespace
> ("http://thisIsMyNameSpace/") ?. Sometimes, it uses a different namespace so
> the .NET can deserialize the type well and as result you get a null
> reference.
>
> Regards,
> Pablo Cibraro
>
http://weblogs.asp.net/cibrax >
> "Jannicke" <Jannicke@discussions.microsoft.com> wrote in message
> news:99D1BFA9-5E2E-488A-B445-5FA5EC4C5A22@microsoft.com...
> > Hi. I have a project that contains a webservice. To test my webservice I
> > have
> > another class in the same project. In the project I have added a
> > webreference
> > to my webservice. In my class file i call the webservice which should
> > return
> > a string value in the response. The problem is that the responsevalue is
> > null
> > even if the webmethod acts like it should do. I have debugged my code and
> > when i debug the webmethod the return value is set correct, but it seems
> > like
> > it can't send the value to the class that calls it. ANY help would be
> > appreciated!
> >
> > This is how i call my webservice:
> >
> > wsReference.MyWebService ws = new swReference.MyWebService();
> > wsReference.AuthHeader au = new wsReference.AuthHeader();
> > au.userName = "testName";
> > au.passWord = "testPW";
> >
> > ws.AuthHeaderValue = au; //Adds the soapheader containg pw and username
> >
> > string response = ws.MyWebMethod( "param1";"param2";"param3");
> >
> > My webservice class looks like this:
> >
> > [WebService(Namespace="http://thisIsMyNameSpace/")]
> > public class MyWebService: System.Web.Services.WebService
> > {
> >
> > public AuthHeader MacCredentials;
> >
> > public MyWebService()
> > {
> > InitializeComponent();
> > }
> >
> > #region Component Designer generated code
> >
> > //Required by the Web Services Designer
> > private IContainer components = null;
> >
> > /// <summary>
> > /// Required method for Designer support - do not modify
> > /// the contents of this method with the code editor.
> > /// </summary>
> > private void InitializeComponent()
> > {
> > }
> >
> > /// <summary>
> > /// Clean up any resources being used.
> > /// </summary>
> > protected override void Dispose( bool disposing )
> > {
> > if(disposing && components != null)
> > {
> > components.Dispose();
> > }
> > base.Dispose(disposing);
> > }
> >
> > #endregion
> >
> >
> > [SoapHeader ("MacCredentials")]
> > [WebMethod]
> > public string MyWebMethod( string param1, string param2, string param3)
> > {
> > string responseText = "Ok";
> > //The caller must be authenticated.
> >
> > // Fail the call if the caller is not authorized
> > if ( MacCredentials.userName.ToLower () != "testUser" ||
> > MacCredentials.passWord.ToLower () != "testPW")
> > {
> > string errorM = "error";
> > return errorM;
> > }
> >
> > //Do something here
> >
> > try
> > {
> > //Do
> > something here
> > }
> > catch( System.Exception e)
> > {
> > return e.Message;
> > }
> >
> > return responseText;
> > }
> >
> > public class AuthHeader : SoapHeader
> > {
> > public string userName;
> > public string passWord;
> > }
> > }
> > }
> >
> > /jannicke
>
>