WCF Restful + Form Post 方法

WCF Restful + Form Post 方法

   index.html ( Testing Web Form )
 
   <form action="/service.svc/form" method="POST">
      <input type="text" name="LoginID" value="" />
      <input type="password" name="LoginPasswd" value="" />
      <input type="submit" value="Submit" />
   </form>
 
   IService.svc
 
   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Runtime.Serialization;
   using System.ServiceModel;
   using System.ServiceModel.Web;
   using System.Text;
   using System.IO;
 
   namespace FormPost
   {
      [ServiceContract]
      public interface IService
      {
         [OperationContract]
         [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "form")]
         string GetData(Stream input);
      }
   }
 
   Service.svc
 
   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Runtime.Serialization;
   using System.ServiceModel;
   using System.ServiceModel.Web;
   using System.Text;
   using System.IO;
   using System.Collections.Specialized;
   using System.Web;
 
   namespace FormPost
   {
      public class Service : IService
      {
 
         [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "form")]
         public string GetData(Stream input)
         {
 
            var streamReader = new StreamReader(input);
            string streamString = streamReader.ReadToEnd();
            streamReader.Close();
 
            NameValueCollection nvc = HttpUtility.ParseQueryString(streamString);
            string LoginID = nvc["LoginID"];
            string LoginPasswd = nvc["LoginPasswd"];
 
            … …
 
            return … … ;
 
         }
 
      }
   }