3

HTTP POST 経由で XML ドキュメントをリッスンする Web ページをセットアップする必要があります。POST アウトする必要はありません。その POST を受信する必要があります。これは何のオブジェクトですか?HTTP ハンドラー、Web サービス、webRequest、ストリームなどを使用する必要がありますか? IIS サーバーを使用する必要があり、C# を好みます。

私はもう試した...

  1. リクエストを送信しておらず、待っているだけなので、WebRequestを使用できるとは思いません。

  2. 「HttpRequest.InputStream」ですが、使い方やどこに置くべきかわかりません。Web サービスまたは asp.net アプリケーションで使用する必要がありますか? http://forums.asp.net/t/1371873.aspx/1に入れました

  3. 簡単な Web サービスを試してみましたhttp://msdn.microsoft.com/en-us/library/bb412178.aspx - しかし、"http://localhost:8000/EchoWithGet?s=Hello, world !」、「Webページが見つかりませんエラー」が表示されます

誰かが役に立つコードやリンクを持っていれば、それは素晴らしいことです!

編集: 別のプログラムから通知を受信しようとしています。

4

2 に答える 2

13

.ASPX ページまたは一般的な.ASHX ハンドラーのいずれかを持つことができる IIS でホストする ASP.NET アプリケーションを作成できます(結果をどのようにフォーマットするかによって、HTML を返すか、それとも何かを返しますか?他のタイプ) を読み取りRequest.InputStream、クライアントからのリクエストの本文を含む を読み取ります。

MyHandler.ashx一般的なハンドラー ( )を作成する方法の例を次に示します。

public class MyHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var stream = context.Request.InputStream;
        byte[] buffer = new byte[stream.Length];
        stream.Read(buffer, 0, buffer.Length);
        string xml = Encoding.UTF8.GetString(buffer);

        ... do something with the XML

        // We only set the HTTP status code to 202 indicating to the
        // client that the request has been accepted for processing
        // but we leave an empty response body
        context.Response.StatusCode = 202;
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
于 2012-04-06T20:43:21.570 に答える
0

ハンドラーをどこで呼び出すか、または使用するかがわかりません。これは私がこれまでに持っているものです...

デフォルト.aspx

<%@Page Inherits="WebApplication1._Default"%>
<%@OutputCache Duration="10" Location="Server" varybyparam="none"%>
<script language="C#" runat="server">
  void Page_Init(object sender, EventArgs args) {

  }     
}
</script>
<html>
  <body>
  </body>
</html>

Default.aspx.cs

namespace WebApplication1  
{
  public partial class _Default : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext contex = Context;
        MyHandler temp = new MyHandler();
        temp.ProcessRequest(context);
    }
  }

    public class MyHandler : IHttpHandler
    {
       public void ProcessRequest(HttpContext context)
       {
         var stream = context.Request.InputStream;
         byte[] buffer = new byte[stream.Length];
         stream.Read(buffer, 0, buffer.Length);
         string xml = Encoding.UTF8.GetString(buffer);

         ... do something with the XML

        // We only set the HTTP status code to 202 indicating to the
        // client that the request has been accepted for processing
        // but we leave an empty response body
        context.Response.StatusCode = 202;
       }

      public bool IsReusable
      {
        get
        {
          return false;
        }
      }
   }
}
于 2012-04-06T21:22:43.757 に答える