how to send custom object to WCF REST Service in browser based url [duplicate]

泄露秘密 提交于 2019-12-06 07:08:02

问题


i have a serializable entity class of employee

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

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);

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


回答1:


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.

You can find more information about query string converters at http://blogs.msdn.com/b/carlosfigueira/archive/2011/08/09/wcf-extensibility-querystringconverter.aspx.




回答2:


This blog post seems to cover what you're looking for.

http://saravananarumugam.wordpress.com/2011/03/04/simple-rest-implementation-with-webhttpbinding/



来源:https://stackoverflow.com/questions/7943554/how-to-send-custom-object-to-wcf-rest-service-in-browser-based-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!