问题
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