C# – Getting POST data from form with WCF Service Application

chtmlwcf

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?

Best Answer

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);
    }
Related Topic