I'm having trouble getting my WCF service to work. In the code below I can call my service's HelloWorld() method and it works, but I cannot call the GetCustomer() method successfully (it just prints "Address:", not the customer name and address. Anyone know how this could be? I do not understand why my service is not passing a customer object to the client. I believe I am implementing what was shown here.If anyone can take a look at this I would really appreciate it. Thanks in advance!
// Service Interface:
[ServiceContract(Namespace="http://www.myservice.com")]
public interface IAddressService
{
[OperationContract]
string HelloWorld();
[OperationContract]
Customer GetCustomer();
}
// Service:
public class AddressService : IAddressService
{
public string HelloWorld()
{
return "Hello World";
}
public Customer GetCustomer()
{
return new Customer()
{
Id = 1,
Address = "1212 Forest Lane Irving TX",
FirstName = "Vladamir"
};
}
}
// Customer class (my custom data object):
[DataContract]
public class Customer
{
private int id;
private string address;
private string firstName;
[DataMember]
public int Id
{
get { return id; }
set { id = value; }
}
[DataMember]
public string Address
{
get { return address; }
set { address = value; }
}
[DataMember]
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
}
//Client code:
class Program
{
static void Main(string[] args)
{
EndpointAddress epa = new EndpointAddress("http://localhost:8000/AddressService/AddressAppService");
IAddressService service = ChannelFactory<IAddressService>.CreateChannel(new BasicHttpBinding(), epa);
Console.WriteLine(service.HelloWorld());
Customer c1 = service.GetCustomer();
Console.Write(c1.FirstName + " Addresss: " + c1.Address);
Console.WriteLine("Press <ENTER> to exit the client.");
Console.ReadLine();
}
}