我有一个简单的基于Windows服务的WCF REST客户端(基于WebServiceHost())。我可以从GET操作接收数据,并在PUT操作中调用正确的方法,但传递的json不会被反序列化为.NET对象。我总是将传入的对象变为空。WFC Rest服务PUT与JSON - 收到的对象始终为空
接收方法有两个参数,一个来自uri,另一个来自接收的json数据。关键正确地进入我的方法。
我打开日志记录,但没有任何反序列化错误。提琴手很高兴,它收到了200响应。我没有看到有什么有趣的东西来看看电线上发生了什么。
我一直在看着围绕这个问题的其他帖子,以及我能看到的东西,我已经正确地设置了一些东西。显然这不是真的,但我看不出有什么缺失/错误。如果只有更多的诊断信息出现,这将会容易得多。我将配置文件调试设置为冗长,但我没有在实际的消息反序列化过程中看到太多内容。
有没有办法进入实际的反序列化过程进一步调试?
或者我的设置在下面有详细说明吗?
服务合同,Send()
方法具有两个参数,一个key
和message
对象:
[ServiceContract]
public interface ILoader
{
[OperationContract]
[WebInvoke(Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Send/{key}")]
string Send(string key, MessageBodyWrapper message);
}
我对消息包装对象数据契约设置:
[DataContract(Name = "MessageWrapper")]
public class MessageBodyWrapper
{
private string _messageBody;
private string _state;
public MessageBodyWrapper()
{
_messageBody = "un-initialized";
}
[DataMember(Name="Message")]
public string Message
{
get { return _messageBody; }
set { _messageBody = value; }
}
public override string ToString()
{
JavaScriptSerializer js = new JavaScriptSerializer(); // Available in System.Web.Script.Serialization;
return js.Serialize(this);
}
}
接口
public class Loader : ILoader
{
private string _state;
public Loader()
{
_state = "initialzied";
}
public string Send(string key, MessageBodyWrapper Message)
{
string ret = "Send here -- Message";
return (ret);
}
}
我使用招送出样品PUT
User-Agent: Fiddler
Content-Type: application/json
Host: localhost:8080
Content-Length: 48
{"Message":"sdsdfsdf"}
我向我的MessageBodyWrapper()类添加了ToString()方法。然后在我的主体中创建一个新对象并序列化它。然后我用Fidder作为另一个测试,但这并没有帮助。我真的认为我的配置存在一些问题,我无法发现。 –