我有一个如下定义的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" 五 " 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,但这正在吃我的午餐。