2
votes

I'm tired of getting POST data with WCF (I'm a newbie) so I really don't know what am I doing wrong. I'm trying to send POST data with this form:

<!doctype html>
<html>
<head></head>
<body>
    <form action='http://localhost:56076/Service.svc/invoke' method="post" target="_blank">
        <label for="firstName">First Name</label>: <input type="text" name="firstName" value="" />
        <label for="lastName">Last Name</label>: <input type="text" name="lastName" value="" />
        <input type="submit" />
    </form>
</body>
</html>

And I'm using WCF Service Application (in VS2008):

    //IService.cs:

    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "invoke", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string GetData(Stream aoInput);
    }
//Service.svc.cs
public class Service : IService
    {
        public string GetData(Stream aoInput)
        {
            using (StreamReader loReader = new StreamReader(aoInput))
            {
                string body = loReader.ReadToEnd();
                var @params = HttpUtility.ParseQueryString(body);
                return @params["FirstName"];
            }
        }
    }

While service executes after I press submit on the form I have no response from the breakpoints in my code. What am I doing wrong?

1
When you perform a POST operation there are no queryStrings evaluated if i am not wrong. Hence there is no response coming back. The parameters during POST are part of the RequestBody and not query stringRajesh

1 Answers

2
votes

I found this other_wcf_stuff. All trick is in web.config (there must be declared binding (only webHttpBinding) and behavior configuration). Also my interface of service is now:

[ServiceContract]
    public interface IService
    {
        [OperationContract]
        string GetData(Stream aoInput);
    }