我可以在WCF服务中使用Json序列化吗? [英] Can I use Json serialization in WCF service?

查看:219
本文介绍了我可以在WCF服务中使用Json序列化吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于WPF的Windows应用程序。我想使用实体框架自我跟踪实体和WCF。我想知道如果使用Json是可能/推荐的?如果是,请协助我;有没有可以帮助的教程?

解决方案

可以使用DataContractJsonSerializer序列化消息。您将不得不使用基于REST的服务(WebHttpBinding),因为SOAP要求XML作为消息有效载荷。



您可以通过WebGet和WebInvoke属性中的设置告诉WCF在服务端使用DatcontractJsonSerializer,但在客户端,您将必须手动将此序列化程序用作REST不具有元数据标准,因此您必须以更加手动的方式创建请求并管理响应。



这里是使用Json和REST支持的合理指南在WCF中



但是,你的驱动程序是什么使用Json? WCF现在更加适用于基于SOAP的交互(尽管WCF 4.5 WebApi会在一定程度上解决这个问题)。由于您的客户是WPF,您似乎没有从使用Json的角度获得一些$ /

I am going develop a WPF windows based application. I want to work with Entity Framework Self Tracking Entities and WCF. I was wondering if using Json is possible/recommended? If yes, please assist me; is there any tutorial that can help?

解决方案

You can use the DataContractJsonSerializer to serialize the messages. You will have to use a REST based service (WebHttpBinding) as SOAP mandates XML as the message payload.

You can tell WCF to use the DatcontractJsonSerializer on the service side by settings in the WebGet and WebInvoke attributes but on the client side you will have to manually use this serializer as REST doesn;t have a metadata standard and therefore you have to create the requests and manage responses in a more manual fashion

Here is a reasonable guide to using Json and REST support in WCF

However, what is your driver to using Json? WCF is much more geared to SOAP based interaction currently (although the WCF 4.5 WebApi is going to address that to quite a degree). As your client is WPF you don't seem to gain alot from using Json

这篇关于我可以在WCF服务中使用Json序列化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆