views:

219

answers:

2

I have a WebInvoke method like this;

[OperationContract]

    [WebInvoke(

        Method = "POST",
        UriTemplate = "/go",
        BodyStyle = WebMessageBodyStyle.Bare,
        RequestFormat = WebMessageFormat.Xml,
        ResponseFormat = WebMessageFormat.Xml

    )]       
    string go(string name);

and I post the data like this;

System.Net.WebClient client = new System.Net.WebClient();

        string reply = client.UploadString(
            "http://localhost/HelloService/Service.svc/go",
            "POST",
            aString);

The question is how can I take the data from posted message in go() method without using a uri template like this;

UriTemplate = "/go({name})"

Because I want to sent large amount of data and I cannot sent it in uri template

A: 

Do you have access to System.Web.HttpContext.Current?

You could try System.Web.HttpContext.Current.Request.Form, or, it looks like you are using XML for your request format, so you may want to try loading an XElement or XmlDocument from the request stream.

(may have the wrong method here, but it exists somewhere in the request object) // .NET 4.0 only XElement el = XElement.Load(HttpContext.Current.Request.GetRequestStream());

LorenVS
I cannot access to System.Web.HttpContext.Current. Do I need.Net4.0?
EEE
+1  A: 

Here is the solution;

[OperationContract]
[WebInvoke(
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
Method = "POST",
UriTemplate="/go"
)]  
string MyWebServiceMethod(string name);

and HTTP POST request is;

POST /go Modify HTTPS/1.1
Content-Type: application/json; charset=utf-8
Host: WebserviceURL
Content-Length: length

{"name":"someName"}
EEE