Web Service: Exposing a remote method of a class
I have a test CustomerService class that looks like
Code:
public class CustomerService : WebService
{
public CustomerService()
{
}
[WebMethod]
public string Status()
{
string s = string.Format("Time: {0}", DateTime.Now);
return s;
}
[WebMethod]
public List<Customer> ListCustomers()
{
return new CustomerDao().FindAll();
}
}
Now, nevermind the DAO class, let's go to Customer class
Code:
public class Customer
{
int number;
Name name = new Name();
public Name Name {
get { return name; }
set { name = value; }
}
public int Number {
get { return number; }
set { number = value; }
}
public Customer()
{
}
}
Now, the Name is
Code:
public class Name
{
string lastName;
string firstName;
string middleName;
public string MiddleName {
get { return middleName; }
set { middleName = value; }
}
public string FirstName {
get { return firstName; }
set { firstName = value; }
}
public string LastName {
get { return lastName; }
set { lastName = value; }
}
public Name()
{
}
public Name(string lastName, string firstName, string middleName)
{
this.lastName = lastName;
this.firstName = firstName;
this.middleName = middleName;
}
public override string ToString()
{
return string.Format("{0}, {1} {2}", lastName, firstName, middleName);
}
}
Using wsdl.exe, I am able to get the CustomerService.cs but NO ToString() method on the Name class. I need this so that I can just
Code:
[Test]
public void TestMethod()
{
foreach (Customer c in new CustomerService().ListCustomers()) {
Console.WriteLine(c.Name.ToString());
}
}
I know I'm missing something. Anyone has the kind heart to help me out? Thanks!
Re: Web Service: Exposing a remote method of a class
If you're using Visual Studio, try removing the service from the Web References and then rediscovering it. Sometimes changes to existing ones don't refresh and the calling class can't see those changes, so you need to grab the reference from scratch in order to use the changes.