C# 在WCF服务中使用JSON而不使用DataContract,但仍使用application/JSON内容类型

C# 在WCF服务中使用JSON而不使用DataContract,但仍使用application/JSON内容类型,c#,json,wcf,rest,content-type,C#,Json,Wcf,Rest,Content Type,根据我对WCF服务的理解,在使用application/json内容类型时,必须使用DataContract方法,例如: [DataContract] public class Thingy { [DataMember] public string Name { get; set; } } [ServiceContract] public interface IThingy { [OperationContract] [WebInvoke(Method = "P

根据我对WCF服务的理解,在使用application/json内容类型时,必须使用DataContract方法,例如:

[DataContract]
public class Thingy
{
    [DataMember]
    public string Name { get; set; }
}

[ServiceContract]
public interface IThingy
{
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "thingy", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    Thingy CreateThingy(Thingy thingy);
}
是否有一种方法仍然能够使用application/json内容类型,但原型应该是:

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "thingy", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    Stream CreateThingy(Stream thingy);
Web.Config文件条目包括:

<service name="ThingySvc.SMSSystem">
    <endpoint address="" behaviorConfiguration="ThingySvc.ThingySvcBehavior" binding="webHttpBinding" contract="ThingySvc.IThingy" />
</service>

<behavior name="ThingySvc.ThingySvcBehavior">
    <webHttp />
</behavior>


我的问题可能重复,但我看不出重复。我想向WCF服务发送一个简单明了的JSON字符串,但使用内容类型“application/JSON”。如果我将内容类型设置为“application/x-www-form-encoded”并传递一个流参数,我就可以做到这一点。本质上,我想做的是在请求体中传递JSON,并使用内容类型“application/JSON”。请您解释一下,为什么要使用此签名
Stream CreateThingy(Stream thingy)
看起来您只希望在
ServiceContract中有一个
OperationContract