0

Webサービスを作成しようとしています。HttpClient Request を Web サービスに送信し、応答も取得できました。

私は何をしたいですか?

userAgent や任意の CustomHeader などの POST リクエストでいくつかの HttpHeaders を送信しています。webserviceメソッドで読みたいヘッダー。ヘッダー リストの取得方法がわかりません。

C# で Web サービスを作成しました。

   public class Service1 :IService1{   
           public string putData(Stream data)
            {
        string response = string.Empty;
        try
        {
            HttpContext ctx = HttpContext.Current;
            string headerValue = ctx.Request.Headers["tej"];              
            StreamReader reader = new StreamReader(data);
            string xmlString = reader.ReadToEnd();
            StringReader sr = new StringReader(xmlString);
            MySqlCommand cmd = new MySqlCommand();
            DataSet ds = new DataSet();

            ds.ReadXml(sr);
            //my logic here....

            return "Passed";
        }
        catch (Exception ex)
        {
           return "Failed";
        }
    }
}

 public interface IService1
{
    [OperationContract]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, BodyStyle =                 WebMessageBodyStyle.Wrapped, UriTemplate = "putdata")]
    string putData(Stream sDatabase); 
}
4

1 に答える 1