0

C#アプリでEWSのプッシュ通知を設定しようとしています。

サーバーから応答を取得し、NetworkStreamを使用してそれを読み取った後、SOAPメッセージでOkを使用してサーバーに応答する必要があります。私が見つけることができる唯一の例は、Microsoft.Web.Services3とSoapEnvelopeを使用しています。私の理解では、これは現在WCFに置き換えられており、(それらを学習するために)新しいテクノロジを実際に使用したいと考えています。

おそらく通知を受け取ったのと同じNetworkStreamを使用して、SOAPメッセージをサーバーに送り返すにはどうすればよいですか?

これが私が試したコードですが、何らかの理由で失敗します。

const string RESPONSE_OK = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope\"><soap:Body>" +
                "<SendNotificationResult xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">" +
                "<SubscriptionStatus>OK</SubscriptionStatus></SendNotificationResult></soap:Body></soap:Envelope>";

responseBytes = encoding.GetBytes(RESPONSE_OK);

             // Send the result
             HTTPResponseStruct _httpResponse;
            _httpResponse.version = "HTTP/1.1";
            _httpResponse.BodyData = responseBytes;

            _httpResponse.Headers = new Hashtable();
            _httpResponse.Headers.Add("Server", "IT12");
            _httpResponse.Headers.Add("Date", DateTime.Now.ToString("r"));
            _httpResponse.Headers.Add("Content-Type", "text/xml; charset=utf-8");
            _httpResponse.Headers.Add("Content-Length", _httpResponse.BodyData.Length);
            _httpResponse.Headers.Add("Connection", "close");


            string HeadersString = _httpResponse.version + " "
               + "200 OK" + "\r\n";

            foreach (DictionaryEntry Header in _httpResponse.Headers)
            {
                HeadersString += Header.Key + ": " + Header.Value + "\r\n";
            }

            HeadersString += "\r\n";

            byte[] bHeadersString = Encoding.ASCII.GetBytes(HeadersString);

            // Send headers   
            clientStream.Write(bHeadersString, 0, bHeadersString.Length);


            // Send body
            if (_httpResponse.BodyData != null)
                clientStream.Write(_httpResponse.BodyData, 0,
                         _httpResponse.BodyData.Length);
           // clientStream.Write(responseBytes, 0, responseBytes.Length);
            clientStream.Flush();

ありがとう、ピーター

4

2 に答える 2

1

Microsoft.Exchange.WebServices.Data(EWSマネージAPIリファレンス)を使用できます

http://msdn.microsoft.com/en-us/library/dd633710%28v=EXCHG.80%29.aspx

于 2011-02-02T13:21:10.387 に答える
1

他の回答を「承認済み」としてマークしましたが、参照しているリンクはストリーミングサブスクリプションについて説明しています。これらは、Exchange2010以降でのみ使用できます。Exchange Server 2007で立ち往生している人のために、CodePlexにプッシュ通知ライブラリがあります。

于 2012-12-20T11:54:08.653 に答える