我有以下WCF REST web服务接口:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(
UriTemplate = "foobar/",
Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare),
]
void PostFoobar(Foobar foobar);
}执行情况:
public class Service : IService
{
public void PostFoobar(Foobar foobar)
{
try
{
Log.MonitoringLogger.Info("foo" + foobar.foo);
Log.MonitoringLogger.Info("bar" + foobar.bar);
}
catch (Exception ex)
{
if (Log.ExceptionLogger.IsErrorEnabled) Log.ExceptionLogger.Error(ex);
}
}
}我的Foobar班:
[DataContract]
public class Foobar
{
[DataMember]
public string foo { get; set; }
[DataMember]
public string bar { get; set; }
}但是,当我从客户端调用Foobar对象时,参数中的Foobar对象似乎始终为空。我试图实现以下方法:
void PostFoobar(String foo, String bar);这一次起作用了!所以我的问题是:为什么当我发送一个JSON对象时,它没有反序列化它?
下面是一个用Wireshark实现的捕获,以查看我的客户端是否真的发送了我所期望的JSON对象:

因此,客户端似乎按预期发送对象:{ "foo":"foo“,"bar":"bar text”}
发布于 2013-09-12 13:28:18
我发现了一些有趣的东西:它适用于chrome插件,简单的REST客户端。我发送了json的数据:
{ "foo": "foo text", "bar" : "bar text" }而且起了作用。
因此,我分析了我的IIS服务器的日志,发现了一个不同之处:没有从我的客户端捕获任何元素。以下对象(在日志中)
<root type="object" xmlns="">
<foo type="string">foo chrome</foo>
<bar type="string">bar chrome</bar>
</root>只有当我从铬客户端调用我的服务时才会出现。
https://stackoverflow.com/questions/18764174
复制相似问题