WCF JSON格式

WCF JSON格式,wcf,rest,Wcf,Rest,我正在用WCF写一些REST服务。这是我的密码 [DataContract] public class Result { [DataMember] public String ErrorCode { get; set; } [DataMember] public Object Data { get; set; } public Result(String msg, Object data) { this.ErrorCode = ms

我正在用WCF写一些REST服务。这是我的密码

[DataContract]
public class Result
{
    [DataMember]
    public String ErrorCode { get; set; }
    [DataMember]
    public Object Data { get; set; }
    public Result(String msg, Object data)
    {
        this.ErrorCode = msg;
        this.Data = data;
    }
}
我这样称呼这个

 [OperationContract]
        [WebInvoke(Method = "POST",
                   UriTemplate = "login",
                   RequestFormat = WebMessageFormat.Json,
                   ResponseFormat = WebMessageFormat.Json,
                   BodyStyle = WebMessageBodyStyle.Wrapped
                   )]
        Result Login(string emailAddress, string password);
{"LoginResult":{"Data":null,"ErrorCode":"[0000]"}}
在我的接口实现类中,我编写了这个

public Result Login(string emailAddress, string password)
        {

            return new Result("[0000]",null);
        }
它给了我一个类似这样的JSON结果

 [OperationContract]
        [WebInvoke(Method = "POST",
                   UriTemplate = "login",
                   RequestFormat = WebMessageFormat.Json,
                   ResponseFormat = WebMessageFormat.Json,
                   BodyStyle = WebMessageBodyStyle.Wrapped
                   )]
        Result Login(string emailAddress, string password);
{"LoginResult":{"Data":null,"ErrorCode":"[0000]"}}
奇怪的是它在根目录下有一个LoginResult,我想要的只是在JSON响应中没有这个LoginResult头的
{“Data”:null,“ErrorCode”:“[0000]”}
。我怎样才能解决这个问题?
谢谢。更新

I just noticed that you have two parameters in your method
1. string emailAddress
2. string password
将这两个参数作为属性添加到对象中,并使用该对象作为参数。 然后应用下面给出的更改。这对你有用

更改下一行:-

BodyStyle = WebMessageBodyStyle.Wrapped

BodyStyle = WebMessageBodyStyle.Bare

是的,那是我首先想到的。但当我改变它时,它给了我这个。“在没有包装器元素的情况下,最多可以序列化一个body参数。请删除额外的body参数,或者将WebGetAttribute/WebInvokeAttribute上的BodyStyle属性设置为Wrapped。”Strage够了,我在其他调用中使用了Bare,看起来还可以……只是这次登录。。。