我有非常常见的情况,我有WCF服务,我已经添加了REST端点并将JSON数据返回到角度应用程序。我的响应对象在Pascal Case中定义,但我想在camelCase中返回JSON响应。无论如何在WCF中这样做?
我没有创建新的Web Api或MVC应用程序的选项,我可以使用options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
轻松完成这是我的代码:
WCF休息端点
IFormsConfigTool.cs
[ServiceContract]
public interface IFormsConfigTool
{
[OperationContract]
[System.ServiceModel.Web.WebInvoke(
Method = "GET",
RequestFormat = System.ServiceModel.Web.WebMessageFormat.Json,
ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json,
BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Bare,
UriTemplate = "getPackageConfig/{superBranch}")]
PackageConfigResponse getPackageConfig(string superBranch);
}
响应类
public class PackageConfigResponse
{
#region Properties
public List<Package> Packages { get; set; }
public MessageInfo Messages { get; set; }
#endregion Properties
}
当前的JSON响应 enter image description here
预期的JSON响应 enter image description here