Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I need to read the http post which is sent to my wcf service.
I need to create a service such a way that it reads the http post is posted.

Please help me to do that

Thanks
Santhosh
Posted

1 solution

Suppose you have service contract like this

MIDL
[ServiceContract]
public interface ISampleService
{
    [OperationContract]
    [WebInvoke(UriTemplate = "invoke")]
    void DoWork(Stream input);
}



And your html form is like

XML
<form method="post" action="Service.svc/invoke">
    <label for="firstName">First Name</label>: <input type="text" name="firstName" value="" />
    <br /><br />
    <label for="lastName">Last Name</label>: <input type="text" name="lastName" value="" />
    <p><input type="submit" /></p>
</form>


Then implementation of your operation contract will be
public void DoWork(Stream input)
{
    StreamReader sr = new StreamReader(input);
    string s = sr.ReadToEnd();
    sr.Dispose();
    NameValueCollection qs = HttpUtility.ParseQueryString(s);
    string firstName = qs["firstName"];
    string lastName = qs["lastName"];
 

}
 
Share this answer
 
Comments
Santhosh Kesavan 8-Jun-11 3:18am    
thanks kiran
Santhosh Kesavan 8-Jun-11 3:19am    
kiran,
do have a sample code for http post to post to the wcf service
Kiran Sonawane 8-Jun-11 3:23am    
whats ur email add?
Santhosh Kesavan 8-Jun-11 4:45am    
yes kiran i got ur sample code, do u have any code to post the data to the service?
Santhosh Kesavan 8-Jun-11 3:26am    
sash2021@gmail.com

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900