使用WCF服务的SerializationException

时间:2011-07-28 10:10:59

标签: .net wcf web-services json

我的WCF服务设置如下:

    [ServiceContract]
    public interface IObjectPresentationService
    {
        [OperationContract(Name="GetFooter")]
        [WebInvoke(Method = "POST",
      BodyStyle = WebMessageBodyStyle.WrappedRequest,
      ResponseFormat = WebMessageFormat.Json)] 
        string GetFooter();
     }

当我在客户端使用添加服务引用时,会生成以下代码:

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IObjectPresentationService/GetFooter", ReplyAction="http://tempuri.org/IObjectPresentationService/GetFooterResponse")]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat=WebMessageFormat.Json)]
        string GetFooter();

但是,当我尝试执行GetFooter()时,我得到以下异常:

  

SerializationException未处理   OperationFormatter遇到无效的Message正文。期待   找到名称为“type”且值为“object”的属性。找到了价值   '字符串'

使用Fiddler我可以看到服务确实返回一个普通的字符串,在开头和结尾都有引号(这应该使它有效json?)。

这可能是配置问题吗?

0 个答案:

没有答案
相关问题