技术开发 频道

WSE 3.0实现远程回调


【IT168技术文档】

  前两天有个好朋友问道关于Web Service实现远程回调,用www.live.com搜索了下。找到一位公司同事MVM(http://blog.joycode.com/mvm/) 两年前写的一篇Blog关于用WSE 2.0在XML Web Services里面实现Callback 。按照这个思路下面用WSE 3.0的版本做了类似的一个实现。

  (A)基本原理
  WSE实现远程回调的原理如下:
  (B)实现技术关键:
  1,WebService维护一个Client SOAP Address List
  2,Client提供一个Soap的Receiver用于接受服务器对于SOAP的调用

  (C)服务段部分代码
  Server.cs
public class Service : System.Web.Services.WebService { private ArrayList Listeners { get { return (ArrayList)Application["Listeners"]; } } [WebMethod] public void AddListener(string listener) { this.Listeners.Add(listener); } [WebMethod] public void Callback() { for (int i = 0; i < this.Listeners.Count; i++) { SoapEnvelope envelope = new SoapEnvelope();     //这里不同于WSE 2.0,在WSE 2.0上实现envelope.Context.Action 和envelope.Context.ReplyTo envelope.Context.Addressing.Action = new Action((string)(this.Listeners[i])); envelope.Context.Addressing.ReplyTo = new System.Uri((string)(this.Listeners[i])); SoapSender peerProxy = new SoapSender(new System.Uri((string)(this.Listeners[i]))); try { peerProxy.Send(envelope); } catch (Exception e) { this.Listeners.RemoveAt(i); } } } }
0
相关文章