我正在使用像这样的WCF .svc类:
[DataContract] public class FunInfo { ... }
[OperationContract, WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
public FunInfo SetInformation(int a, int b) { ... }
当我收回我的JSON时,它看起来像这样:
{"SetInformationResult":{ ... } }
我的问题是:SetInformationResult来自哪里,我可以控制它的名字而无需重命名我的类吗?例如,“d”模仿ScriptService的作用?
编辑:对于后代,我发现的相关链接:How can I control the name of generic WCF return types?
答案 0 :(得分:16)
名称来自您的操作名称,并附加了“Result”。您可以使用方法返回时的[MessageParameter]
属性重命名它:
[OperationContract, WebInvoke(...)]
[return: MessageParameter(Name = "d")]
public FunInfo SetInformation(int a, int b) { ... }