これは非常に単純かもしれませんが、WCF レスト サービスでクエリ文字列値を読み取る方法が見つかりません。私は次のことを試しましたが、喜びはありません
HttpContext.Current.Request.QueryString["name"]
これは非常に単純かもしれませんが、WCF レスト サービスでクエリ文字列値を読み取る方法が見つかりません。私は次のことを試しましたが、喜びはありません
HttpContext.Current.Request.QueryString["name"]
このようなものがうまくいくはずです。UriTemplate を使用する必要があります。以下はWCFサービスです
【サービス契約】
インターフェイス IPing
{
【運営契約】
[WebInvoke(Method="POST", UriTemplate="stuff?n={名前}&q={数量}")]
void AddStuff(文字列名、文字列量、ストリームデータ);
}
クラス PingService : IPing
{
public void AddStuff(文字列名、文字列量、ストリームデータ)
{
Console.WriteLine("{0} : {1}", 名前, 数量);
Console.WriteLine("データ ...");
使用 (StreamReader sr = 新しい StreamReader(データ))
{
Console.WriteLine(sr.ReadToEnd());
}
}
}
そして、クライアント
static void Main(string[] args)
{
WebRequest req = WebRequest.Create("http://localhost:9000/ping/stuff?n=rich&q=20");
req.Method = "POST";
req.ContentType = "text/html";
using (StreamWriter sw = new StreamWriter(req.GetRequestStream()))
{
sw.WriteLine("こんにちは");
}
req.GetResponse();
}