By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 2,082 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Problems with response from webservice.

P: n/a
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
Aug 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <Ja******@discussions.microsoft.comwrote in message
news:99**********************************@microsof t.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

Aug 21 '06 #2

P: n/a
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" <Ja******@discussions.microsoft.comwrote in message
news:99**********************************@microsof t.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


Aug 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.