Sto scrivendo un servizio web che ha molti metodi. Sono tutti impostati simile al seguente:Come impostare il RequestFormat predefinito per un ServiceContract WCF?
[OperationContract]
[WebInvoke(
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "x/y/z")]
void someMethod(int x, int y, int z);
Quello che voglio fare è semplicemente impostare il valore predefinito BodyStyle
/RequestFormat
/ResponseFormat
tutto nel file web.config. Ora, so che posso fare questo:
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
Ma non sembra essere un attributo per il RequestFormat. Come posso impostare il valore predefinito da RequestFormat
a JSON?
Grazie per il chiarimento! Quindi, finché il corpo specifica il formato "application/json", WCF lo rileverà automaticamente, corretto? –
Una curiosità interessante che ho trovato dal tuo link: "Se non viene specificato alcun formato predefinito sull'operazione, viene utilizzato il valore della proprietà DefaultOutgoingResponseFormat." Quindi, in sostanza, se il poster non specifica il tipo di contenuto e non c'è alcun RequestFormat sull'operazione, in realtà prenderà il formato da defaultOutgoingResponseFormat. Interessante. –