I have defined the following Interface
[ServiceContract]
public interface IHealthProducts
{
[OperationContract()]
ResponseClass OrderSelfSignedHealthCertificate();
}
Which returns the following type
[MessageContract]
public class ResponseClass
{
[MessageBodyMember]
public string AnimalSpeciesCode
{
get;
set;
}
[MessageBodyMember]
public int VBN
{
get;
set;
}
}
I expected that the generated client code would expose the OrderSelfSignedHealthCertificate method in the following way:
HealthProductsClient client = new HealthProductsClient();
ResponseClass response = client.OrderSelfSignedHealthCertificate();
Instead, the properties of ResponseClass aren’t wrapped in the ResponseClass, but exposed like so:
string OrderSelfSignedHealthCertificate(out int VBN)
When I exchange the MessageContract for a DataContract attribute and the MessageBodyMember for a DataMember attribute, I get the expected behaviour (ResponseClass response type).
I need the MessageContract however, because I need to put some of the properties in the SOAP header.
Am I doing something wrong? Is this normal behaviour? How do I get a ResponseClass return type, when using a MessageContract?
Any help greatly appreciated.
When your
[MessageContract]contains more than one[MessageBodyMember], then WCF will return the first one as return value from the service call (AnimalSpeciesCodein your case), and all others are returned asoutorrefparaemters.You can solve this by having only a single
[MessageBodyMember]in your message contract that encapsulates all items you need to have return, something like this:In this case, the
CompoundDatashould be the return value from your service call – containing both elements you need.