I would suggest a slightly different approach. Use a class that contains the customer information and decorate it with the [DataContract]
attribute. You can return the customer object to your client, and the client can then access the properties in the object to get the relevant data.
For example, you could have a class like this:
[DataContract(Namespace = "http://namespacename/")]
public class Customer
{
[DataMember]
public string Name { get; set; }
[DataMember]
public CustomerAddress { get; set; }
[DataMember]
public CustomerContact { get; set; }
// Other properties as desired/needed\
}
A couple of things to point out. First, it looks like most any other class (just one with nothing but properties), but the class is decorated with the [DataContract]
attribute and each property is decorated with the [DataMember]
attribute. Only properties that are decorated with the [DataMember]
attribute will be serialized by the DataContractSerializer.
Secondly, you can have nested classes in a Data Contract - note the CustomerAddress
and CustomerContact
properties. Both of these would be Data Contracts as well.
For example:
[DataContract(Namespace = "http://namespacename/")]
public class CustomerAddress
{
[DataMember]
public string City { get; set; }
// other properties
}
Then in your service you could have a method to get the customer information, for example:
public Customer GetCustomerInfo(string customerID)
{
// Code to get customer data, populate CustomerInformation and return it.
}
In your client, you would then do:
MyServiceClient client = new MyServiceClient();
Customer customerInfo = client.GetCustomerInfo("12345");
The client would then access the various parts of the data in the same way you would any other instance of a class with properties:
string name = customerInfo.Name;
string city = customerInfo.Address.City;
string phone = customerInfo.Contact.EmailAddress;
No need to use enums here, simply work with the object returned by the proxy from your service as you would with any other C# class. Note that generally speaking, Data Contracts don't contain methods or constructors.
See also Using Data Contracts
On a final note, your service should implement the interface, and that is what the client will be built upon, not the interface - in other words, IsvcService data = new IsvcService();
should look like svcService data = new svcService();
, where svcService
implements the contract in the interface IsvcService
.