I have a web service with a method that has two string parameters. When I'm debugging, I can see in my calling method where it passes two string values into the method, but actually the WebMethod just gets null for both values. Here is some code:
WebMethod
[WebMethod(Description = "Set username and password for validation purposes.")]
public void Login(string uname, string pword)
{
username = uname;
password = pword;
}
Calling Method
NewsletterEmailSubscribers nes = new NewsletterEmailSubscribers();
nes.Login("Username", "Password");
What am I doing wrong here?
--EDIT--
Adding more code.
The web service:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class NewsletterEmailSubscribers : WebService
{
private static string username, password;
public NewsletterEmailSubscribers()
{
}
/// <summary>
/// Logins the specified username.
/// </summary>
/// <param name="username">The username.</param>
/// <param name="password">The password.</param>
[WebMethod(Description = "Set username and password for validation purposes.")]
public void Login(string uname, string pword)
{
username = uname;
password = pword;
}
/// <summary>
/// Adds subscriber email account.
/// </summary>
/// <param name="emailAddress">The email address</param>
/// <param name="newsletterType">The newsletter they have signed up to receive</param>
/// <param name="validationCode">The validation code</param>
[WebMethod(Description = "Initial add of subscriber email address and newsletter signing up for.")]
public void AddSubscriber(
string emailAddress,
string newsletterType,
string validationCode)
{
// Check some values
//Authenticate user, will throw exception if the user is invalid
using (SOAValidation validation = new SOAValidation())
{
validation.ValidateConnection(validationCode, username, password, "Full");
}
OracleParameterCollection parameters = new OracleParameterCollection();
parameters.AddWithValue("subscriber_email", emailAddress);
parameters.AddWithValue("newsletter_type", newsletterType);
Database.ExecuteQuery("dw.newsletter_pkg.newsletter_subscriber_add", parameters);
}
}
Webpage using the service (NewsletterEmailSubscribers)
private void SubmitEmail(string email)
{
if (ValidateEmail(email))
{
try
{
NewsletterEmailSubscribers nes = new NewsletterEmailSubscribers();
nes.Login("Username", "Password");
string validationCode;
using (Cokesbury.RemoteValidation.Validator validator = new Cokesbury.RemoteValidation.Validator())
{
validationCode = validator.ValidationCode(System.Configuration.ConfigurationManager.AppSettings["PasswordSalt"].ToString());
}
// submit to db
nes.AddSubscriber(email, "FICT", validationCode);
// Switch to confirm message
mvPage.SetActiveView(vwThankYou);
}
catch (Exception ex)
{
mvPage.SetActiveView(vwFail);
bool rethrow = ExceptionPolicy.HandleException(ex, "Presentation Services Exception Policy");
if (rethrow)
{
throw (ex);
}
}
}
else
lblEmailError.Visible = true;
}
Did you create this webservice then hook it up to your other code, or have you designed the webservice to use the same interface as another?
I did the latter once and changed the capitalisation of the parameters in the WebMethod, which lead to me receiving null instead of the correct values.
It happened to me just today and in the end the problem was solved by simply updating the service (as Darin suggested). What happened was that I renamed some parameters in the WebMethod but the client was still using the old name for sending the request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With