2

我有一个 WCF 服务定义如下,我知道它正在工作(产生有效结果):

[ServiceContract(Namespace="XXX.CES.Applet")]
public interface IAppletService
{
    [OperationContract(Action = "GetDefinitionJSON")]
    [WebGet(UriTemplate = "/GetDefinitionJSON?request={jsonRequest}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    string GetAppletDefinitionJSON(string jsonRequest);
}

我定义了以下控制器,可以使用 FireBug 验证它是否到达服务并且响应是我期望的(JSON 字符串):

angular.module('Applet',['ngResource']);
function AppletController($scope,$resource) {
  $scope.url = 'http://localhost/CESAppletService/AppletService.svc/:action';
  $scope.appletRequest =
  {
    AppletName: 'FPTotalForgeTime',
    ModelName: 'CES_ProtoType_Rings_Model',
    EntityName: 'ForgeWCTimes_ForgeTimeTotal',
    EntityType: 'Decimal',
    Value: ''
  };
  $scope.getDefinition = $resource($scope.url,
    {action:'GetDefinitionJSON',request:angular.toJson($scope.appletRequest),callback:'JSON_CALLBACK'});
  $scope.AppletInputs = $scope.getDefinition.get();
}

当我在 FireBug 中查看生成的 $scope.AppletInputs 或通过在页面中呈现它们时,该对象如下所示(仅部分):

""" 1 "{" 2 "\" 3 """ 4 "A" 5 "p" 6 "p" 7 "l" 8 "e" 9 "t" 10 "I" 11 "n" 12 "p " 13 "u" 14 "t" 15 "s" 16 "\" 17 """ 18

实际服务结果为:

"{\"AppletInputs\":[{\"AllowedValues\":  [],\"EntityName\":\"Forge_OD\",\"InputLabel\":\"OD\",\"InputType\":\"Decimal\",\"Value\":null},{\"AllowedValues\":[],\"EntityName\":\"Forge_ID\",\"InputLabel\":\"ID\",\"InputType\":\"Decimal\",\"Value\":null},{\"AllowedValues\":[],\"EntityName\":\"Forge_Face\",\"InputLabel\":\"Face\",\"InputType\":\"Decimal\",\"Value\":null},{\"AllowedValues\":[\"G43400XXX\",\"S30403XXX\",\"S31603XXX\",\"N06625XXX\",\"A96061XXX\",\"G43400GE2\",\"E16587M01\"],\"EntityName\":\"MaterialGrade\",\"InputLabel\":\"Grade\",\"InputType\":\"List\",\"Value\":null}],\"AppletName\":\"FPTotalForgeTime\",\"AppletType\":\"Decimal\",\"AppletVersion\":\"\",\"EntityName\":\"ForgeWCTimes_ForgeTimeTotal\",\"ModelName\":\"CES_Prototype_Rings_Model\"}"

我做错了什么,我该如何解决?我真的很想在这个项目中使用 Angular,但这是在吃我的午餐。

4

0 回答 0