Reputation: 17932
How to call WCF Data Services Operations from the WCF Services Client ?
I have this operation on my service :
[WebInvoke(Method="POST")]
public void Add(int ContractId, string Partners)
{
...
}
How do I call this operation from my client ? my client is a C# based application. bearing in mind that the Partners string is a very very long one. it's a concatenation of the partners Ids like : "1,2,3,4, ... 990".
I have tried doing the following :
string requestString = string.Format("Add?contractId={0}&Partners={1}", ContractId, groupIdParam);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceUrl +
requestString);
request.Method = "POST";
var response = request.GetResponse();
but I receive the error : "HTTP 414 : Request Uri too long"
Upvotes: 2
Views: 3545
Reputation: 4459
Actually, you aren't performing a POST-request. A POST request provides the information in the request-body, which is why it is used especially for large data-sets. You have to provide both contractId
and partners
in the request-body. You can use the HttpWebRequest.GetRequestStream()
method to get a stream, to which you then write the parameters.
This link http://en.wikipedia.org/wiki/POST_(HTTP) describes the structure used to specify the name-value pairs within the request-body.
So you could write something like this (untested):
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceUrl + "Add");
using (Stream bodyStream = request.GetRequestStream())
using (StreamWriter writer = new StreamWriter(bodyStream))
{
writer.Write("contractId: {0}", contractId);
writer.Write("partners: {0}", String.Join(",", partners);
}
request.GetResponse();
Edit As Vitek Karas stated this isn't possible. I just looked at it from a client perspective not the service.
Upvotes: 1
Reputation: 13320
Currently OData doesn't support passing parameters for service operations (that's what the WebInvoke method is) in the body of the POST request. All the parameters are passed in the URL, and thus they have to be pretty small (usually something below 2048 characters, depends on your web server, proxies and so on).
Upvotes: 3