我正在使用 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?
最佳答案
该名称来自您的操作名称,并在其后附加了“Result”。您可以在方法返回时使用 [MessageParameter]
属性重命名它:
[OperationContract, WebInvoke(...)]
[return: MessageParameter(Name = "d")]
public FunInfo SetInformation(int a, int b) { ... }
关于c# - 如何使用 WCF 更改外部对象的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9896828/