How can I create the service contract to be in XmlSerializerFormat as well as WebMessageFormat.Json within a WCF RESTful service.
What I need is to call the "CallADSWebMethod" operation contract from code behind of ASP.Net 1.1 which needs to be XML serialized and from jQuery ajax which is Json serialized.
SERVICE CONTRACT
[ServiceContract, XmlSerializerFormat]
public interface IService
{
[OperationContract, XmlSerializerFormat]
[WebInvoke(UriTemplate = "/CallADSWebMethod",
Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json)]
VINDescription CallADSWebMethod(string vin, string styleID);
}
Endpoint Info
<endpoint address="basic"
binding="basicHttpBinding"
name="httpEndPoint"
contract="ADSChromeVINDecoder.IService" />
<endpoint address="json"
binding="webHttpBinding"
behaviorConfiguration="webBehavior"
name="webEndPoint"
contract="ADSChromeVINDecoder.IService" />
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
What you can do is specify your Web Service like this:
However, what I would suggest you to do is specify 2 different endpoints: one for the XML serialized data and another for JSON serialized data. Come on dude, you are using the REST architecture.....why not make full use of it??!
This can actually be done without a dual declaration as shown in this answer by setting the
webHttpBehavior
'sautomaticFormatSelectionEnabled
property totrue
.