I want to pass/retrieve an instance of the following class through a wcf service. The object should carry the methods that are defined by its class also. is it possible? suppose the following class:
[DataContract]
public class MyClass
{
[DataMember]
public string Name;
public MyClass()
{
}
public MyClass(string name)
{
this.Name = name;
}
public void SetName(string name)
{
this.Name = name;
}
public string GetName()
{
return this.Name;
}
}
[ServiceContract]
public interface IMyService
{
[OperationContract]
MyClass GetMyClassInstance();
}
public class MyService:IMyService
{
public MyClass GetMyClassInstance()
{
return new MyClass("hello");
}
}
Now, when I add a reference to MyService in my client application project, the data contract MyClass will be generated, along with the service client, say MyServiceClient, so, and i do the following:
MyServiceClient client=new MyServiceClient();
MyClass myClass1= client.GetMyClassInstance();
But my real question is, after getting the result from the service, whether this is possible(?) :
myClass1.SetName("oops!!!");
while transmitting data contracts, will the methods in them also be transmitted? My Business objects contain methods too, and they need to be passed through WCF. Is there a way? Is passing BOs such as this through WCF a good practice? Thanks in advance!
WCF exchanges XML (or JSON) documents. The method values marked with 'DataMember' will be in the document. No code within a method is serialized.
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