I'm using a WCF .svc class like so:
我正在使用WCF .svc类,如下所示:
[DataContract] public class FunInfo { ... }
[OperationContract, WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
public FunInfo SetInformation(int a, int b) { ... }
When I get my JSON back, it looks like this:
当我收回我的JSON时,它看起来像这样:
{"SetInformationResult":{ ... } }
My question is: Where did SetInformationResult come from, and can I control it's name without renaming my class? To "d", for instance, to mimic what the ScriptService does?
我的问题是:SetInformationResult来自哪里,我可以控制它的名字而无需重命名我的类吗?例如,要“d”模仿ScriptService的功能?
EDIT: For posterity, relevant links I've found since: How can I control the name of generic WCF return types?
编辑:对于后代,我发现的相关链接:我如何控制通用WCF返回类型的名称?
1 个解决方案
#1
16
The name came from your operation name with "Result" appended to it. And you can rename it by using the [MessageParameter]
attribute on the return of the method:
名称来自您的操作名称,并附加“Result”。您可以使用方法返回时的[MessageParameter]属性重命名它:
[OperationContract, WebInvoke(...)]
[return: MessageParameter(Name = "d")]
public FunInfo SetInformation(int a, int b) { ... }
#1
16
The name came from your operation name with "Result" appended to it. And you can rename it by using the [MessageParameter]
attribute on the return of the method:
名称来自您的操作名称,并附加“Result”。您可以使用方法返回时的[MessageParameter]属性重命名它:
[OperationContract, WebInvoke(...)]
[return: MessageParameter(Name = "d")]
public FunInfo SetInformation(int a, int b) { ... }