2

I've WCF service operation defined in a simple way like

[ServiceContract(Namespace = "http://contoso.com")]
interface ICalculator
{
  [OperationContract]
  AddResp Add(AddRqst addRequestDummyName);
}

where AddRqst is defined as

[DataContract]
class AddRqst
{
    [DataMember]
    public decimal A { get; set; }
    [DataMember]
    public decimal B { get; set; }
}

and the problem I see is that the way WCF serializes and the way it expects requests are wrapped by the parameter name like so (this is from memory)

<Add>
  <addRequestDummyName>
     <A>1</A>
     <B>1.5</B>
  </addRequestDummyName>
</Add>

I can't distribute a schema for this file because WCF likes to add and expects that extra wrapper for the parameters. It should look like I designed to be, like so

<Add>
   <A>1</A>
   <B>1.5</B>
</Add>

I'm aware of MessageContract and I've tested that by changing AddRqst (and also AddResp) to the following removes the wrapping because by using messagecontracts you assume just 1 contract.

[DataContract]
[MessageContract]
class AddRqst
{
    [DataMember]
    [MessageBodyMember]
    public decimal A { get; set; }
    [DataMember]
    [MessageBodyMember]
    public decimal B { get; set; }
}

My question is the following. Is there way to do this just with datacontracts? All my operations have 1 parameter. If not, is the way I modified AddRqst the best way to do this?

Ed Fox
  • 173
  • 1
  • 9
  • *I can't distribute a schema for this file because WCF likes to add and expects that extra wrapper for the parameters* - why can't you distribute this schema? If not as-is, how should it look? – tom redfern Sep 16 '15 at 07:16
  • 1
    @TomRedfern, I've clarified it in the post. Basically, WCF is expecting the wrapper for the parameter name (I believe they call this rpc-style formatting) where I never intended for that to be in the message. – Ed Fox Sep 16 '15 at 12:29

0 Answers0