Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the outer object's name using WCF?

I'm using a WCF .svc class like so:

[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:

{"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?

EDIT: For posterity, relevant links I've found since: How can I control the name of generic WCF return types?

like image 811
Scott Stafford Avatar asked Mar 27 '12 20:03

Scott Stafford


1 Answers

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:

[OperationContract, WebInvoke(...)]
[return: MessageParameter(Name = "d")]
public FunInfo SetInformation(int a, int b) { ... }
like image 137
carlosfigueira Avatar answered Oct 31 '22 04:10

carlosfigueira