I have a RESTful service that has been around for a short while, returning json whenever its methods are called. Just lately i've added a new method, written in exactly the same manner as the others, but it only responds in xml.
Here are the existing method interface definitions:
[ServiceContract]
public interface IAccess
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetRunList?username={username}&FromRun={FromRun}&ToRun={ToRun}&Project={Project}")]
List<RunInfo> GetRunList(string username, int FromRun, int ToRun, string Project = null);
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetPressureTap?RunNumber={RunNumber}")]
ServicePressureTapMap GetPressureTap(int RunNumber);
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetPressureTapByAttitude?RunNumber={RunNumber}&FRH={FRH}&RRH={RRH}&Yaw={Yaw}&Steer={Steer}&Roll={Roll}&Exhaust={Exhaust}")]
List<ServiceAttitudePressureTap> GetPressureTapByAttitude(int RunNumber, decimal FRH, decimal RRH, decimal Yaw, decimal Steer, decimal Roll, decimal Exhaust);
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetPresTapImage?RunNumber={RunNumber}&MapGuid={MapGuid}&MapName={MapName}&Version={Version}")]
Stream GetPresTapImage(int RunNumber, string MapGuid, string MapName, int Version);
}
and all I've done is added the following new method to the bottom:
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetRunConfigs?RunNumber={RunNumber}")]
List<ServiceRunConfig> GetRunConfigs(int RunNumber);
The returned classes have all been declared in the same manner. Only the new method comes back as XML. Have I missed something glaringly obvious?
It turns out, after much searching that I needed to add this:
<endpointBehaviors>
<behavior name="endpointBehavior">
<enableWebScript />
<webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
to my web.config, despite having the WebInvoke line in the Interface that does eactly the same thing. Go figure...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.