2012-03-11 15 views
1

WCFでPOSTデータを取得するのはうんざりです(私は初心者です)ので、何が間違っているのか分かりません。私はこのフォームでPOSTデータを送信しようとしている:WCFサービスアプリケーションでフォームからPOSTデータを取得する

<!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> 

そして、私は(VS2008で)WCFサービスアプリケーションを使用しています:

 
    //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"]; 
      } 
     } 
    } 

私は上の送信]を押した後、サービスの実行中私のコード内のブレークポイントからの応答はありません。私は間違って何をしていますか?

+0

POST操作を実行すると、私が間違っていないと評価されたqueryStringsはありません。したがって、返信はありません。 POST中のパラメータはRequestBodyの一部であり、クエリ文字列ではありません – Rajesh

答えて

1

これが見つかりましたother_wcf_stuff。すべてのトリックはweb.configにあります(バインディング(webHttpBindingのみ)とビヘイビア設定が宣言されている必要があります)。また、私のサービスのインターフェイスは今:

 
[ServiceContract] 
    public interface IService 
    { 
     [OperationContract] 
     string GetData(Stream aoInput); 
    } 
関連する問題