【发布时间】:2018-10-24 16:28:28
【问题描述】:
我有一个 RESTful 服务,它已经存在了一段时间,只要调用它的方法就会返回 json。就在最近我添加了一个新方法,编写方式与其他方法完全相同,但它只在 xml 中响应。
以下是现有的方法接口定义:
[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);
}
我所做的只是在底部添加了以下新方法:
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetRunConfigs?RunNumber={RunNumber}")]
List<ServiceRunConfig> GetRunConfigs(int RunNumber);
返回的类都以相同的方式声明。只有新方法以 XML 形式返回。我错过了什么明显的东西吗?
【问题讨论】:
-
您是否使用正确的 Accept 标头调用 API?
-
是的,它设置为 json。
标签: c# rest web-services