RESTful C#服务未在JSON中响应

时间:2018-10-24 16:28:29

标签: c# rest web-services

我有一个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形式出现。我错过了明显的东西吗?

1 个答案:

答案 0 :(得分:1)

经过大量搜索后,我发现需要添加它:

  <cffunction name="initCurrencyRecordset" access="private" output="false" returntype="void">
    <!--- <cfquery name="qry" datasource="#variables.dsn#">
        select distinct c.LOCAL_CUR as code, ISNULL(c.LocalConversionToUSD, c.x) as rate
        from SCS_FM.dbo.currency c
        join scs_fm.dbo.currency_code cc
            ON c.local_cur = cc.currency_code
        order by LOCAL_CUR
    </cfquery> --->

    <cfstoredproc procedure="usp_Rates_InitCurrencyRecordset_Qry" datasource="#variables.dsn#">
    <cfprocresult name="qry" >
    </cfstoredproc>

    <cflock scope="application" type="exclusive" timeout="20">
        <cfset application.qry.currency = duplicate(qry) />
    </cflock>
</cffunction>   

到我的web.config,尽管接口中有WebInvoke行,但实际上行是相同的。走吧...