如何在基于浏览器的 url 中将自定义对象发送到 WCF REST 服务 [英] how to send custom object to WCF REST Service in browser based url

查看:25
本文介绍了如何在基于浏览器的 url 中将自定义对象发送到 WCF REST 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个雇员的可序列化实体类

i have a serializable entity class of employee

public class Emp
{
  public int Id{get; set;}
  public string Name{get;set;}
}

我想将这个类的对象从浏览器发送到 WCF REST 服务,以测试下面给出的添加方法

i want to send object of this class to WCF REST Services from browser to test my add method which is given below

    [WebInvoke(Method = "POST", UriTemplate = "Employee/")]
    [OperationContract]
    string SaveEmployee(Emp Employee);

谁能告诉我如何在基于浏览器的 url 中将自定义对象发送到 WCF REST 服务

can anyone please tell me how to send custom object to WCF REST Service in browser based url

推荐答案

如果要在 URL 中发送复杂对象(而不是在消息正文中),首先,这通常是一个坏主意(对象可能很大,URI 有大小限制,您最终可能会遇到该限制).但是,如果这确实是您想要的,您可以在您的服务中使用自定义 QueryStringConverter,它将知道如何在查询字符串参数和您的对象之间进行转换.

If you want to send the complex object in the URL (not in the message body), first of all, this is usually a bad idea (objects can be large, URIs have a size limit which you may end up hitting). But if this is really what you want, you can use a custom QueryStringConverter in your service which will know how to convert between the query string parameters and your object.

您可以在 http://blogs.msdn.com/b/carlosfigueira/archive/2011/08/09/wcf-extensibility-querystringconverter.aspx.

这篇关于如何在基于浏览器的 url 中将自定义对象发送到 WCF REST 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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