分享
 
 
 

[收藏]SOA:The Subscriber-Publisher Model, Introduction and Implementation

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

SOA: The Subscriber-Publisher Model, Introduction and Implementation

By DGoins

This article explains a brief introduction to SOA and a Subscriber-Publisher model, along with how to implement one using WSE Soap Receiver and WSE Soap Sender classes inside a Windows .NET Application.

Download source files - 30 Kb IntroductionThere’s a new buzzword going around the Developer’s ear. Have you heard it yet? It’s called SOA. It is an acronym for Service Oriented Architecture. This new concept is not really new; it is old in its definition; however the marketing departments of all the big wig companies are re-singing its tune. Microsoft is singing its SOA pop song with .NET building blocks, WSE, ASP.NET and XML. IBM is using another artist called On Demand, and others are following suit as well.

Traditional Distributed ApplicationsThis is new way in thinking especially for a Component architect. Let’s think about it for a second. In Object Oriented Programming from a windows developer perspective, we designed basic Com applications and Com Components around a basic three tier approach. Three Layers: one called the user interface layer. The second called the business logic layer, and the third known as the data layer. Our basic design was simple in concept, if a class had code that interacted with the User interface such as a windows application, or a web page, then we wrote the code on the user interface side. We wrote the code in the windows form, or in DHTML or some other user interface component. On the other hand, if we had logic that dealt with business rules, processes, day to day logic that was the real problem we were trying to solve, we’d place that code in one to many separate components within our business layer, and install that file on a business logic server such as MTS/COM+ services. Last, any logic that dealt with accessing a data source, such as a file, database, server and etc, we’d place that on the server or in a component that ran on the server like using stored procedures.

In OOP, we dealt with many sometimes frustrating terms and concepts. We had to learn Abstraction, Inheritance, Implementation, Encapsulation, Interfaces, Composition, Aggregation and other terms. OOP became so complex that we created diagrams to visually represent all of these terms and conditions called UML. We invested a lot of time and effort, and learning into this paradigm, yet, we still ran into One MAJOR subtly, one major flaw: Interoperability.

COM did not communicate with EJB, ISAM databases did not communicate with COM, CRM systems did not communicate with EJB, nor COM. These technologies did not allow for a smooth communication pattern automatically. We had to finesse and “tweak” each technology to be able to link these disparate designed systems together. The effort and hard work to make this possible caused many strains, and morphing of technologies. Even to the point where some technologies had many add-on features that are a 180 degree turn from its original designed architecture. Just look at ADO from its first versions to its current one, version 2.8 or so, and the most important change from COM technology to .NET. This eventually led to the inevitable.

SOA IntroductionA new paradigm in software design: SOA. So you mentioned all these songs the big wig companies are singing what are they all about? SOA is new way in designing systems. We now think of a system as a well designed, suite of components that is entirely based off of message communication patterns of what a component does (service). It is an idea to center the design of a system(s) on an “orchestrated” suite of services through message communication. These services talk to each other by passing Xml forms of messages back and forth to each other; this is the focal point.

An SOA System

The image to the left shows a standard depiction of a service, with three prongs sticking out from a triangle. These stubs, or points are known as “Endpoints” or “touchpoints”. They are the portals that allow the xml messages to come into and be sent out of some network using any protocol. This is quite the opposite of Distributed COM, where we were forced to use a proprietary protocol, and a special port to send network packets of data across the wire.

We could talk about services and how to architect them and all the new benefits that SOA offers, however the main point of this introduction is to talk about how these services talk to one another: messages. The basis of a message is Xml. Xml is the format, and within this format we have a very specific format called Simple Object Access Protocol (SOAP). SOAP messages contain all data needed to perform some unit of work. It may also contain security specifics like username and password, certificate information, and other secure concepts such as encryption and hashing.

SOAP messages give different platforms such as Unix a way to communicate with others like Microsoft. SOA, and SOAP solves our interoperability problems. The data being passed is all text, and all platforms understand text. Knowing this, the industry has comprised a set of templates, or models of ways in which these messages can pass back and forth. These models are known as Message Exchange Patterns.

Message Exchange PatternsThere are many Message Exchange Patterns (MEP). There is the first implementation of SOA called Xml web services which uses the Request/Response (Remote Procedure Call) MEP. There is also the Dead Letter Channel pattern, where a message is sent to a service, and any errors that occur during the processing of the message are sent to a special “node” or Channel. These errors, more often referred to as Soap Faults are then queued on to a stack. A client application can then retrieve the messages from this queue. There is the Message Router pattern where a message is routed to another service(s) based off of its content, or security credentials. There is the Message Splitter pattern, which splits or combines messages and sends them to other destinations, and most notably, there is the Publisher-Subscriber pattern.

The Publisher-Subscriber pattern is where a message comes into a service to notify it that it wants to listen for “messages that a publisher broadcasts to its listeners”. A Client application sends a “subscription” request message about who it is, and where it can receive these “responses” from the publisher. The application, be it physically installed on the Client or the Server, can then run, and wait on the Publisher service to generate these responses and send it back to its subscribers.

Client Application makes a Subscription Request

The Publisher service would then execute its logic and eventually loop through its collection of subscribers and send the message on. The publisher service may even send a “Fire and Forget” type of message to all the subscribers. This is because the Publisher service may not necessarily be concerned with who gets the message successfully, such as message confirmation.

Publisher service sends a copy of the message to subscribers

Implementation DetailsWith Microsoft’s implementation of the community Standard: WSA, we can implement the Publisher Subscriber model of SOA. Microsoft implements this standard using an Add-on tool called Web Service Enhancements (WSE). Microsoft is currently in version 2.0 service pack 2 of the WSE toolkit, which is the version we’ll use to implement this model.

WSE gives us many classes and technologies we can use inside of a .NET based application. The two classes we’ll focus on is a SoapReceiver class and the SoapSender class.

SoapReceiversA SoapReceiver is a class that inherits/implements from the IHttpHandler interface. (see my article on using WSE with SimpleHandlerFactory) This class provides all the functionality you need to receive soap messages. To use this class just create a custom class and inherit from the SoapReceiver class. This class asks that you override the Receive method. This is the method that receives the soap message from a SoapSender class. Here is the signature of the Receive Method:

The receive method, takes in a WSE SoapEnvelope class as its argument, which is the Soap message passed in by the SoapSender. The SoapEnvelope class inherits from the System.Xml.XmlDocument class and contains many properties and instance methods that allow a developer to read and parse the Xml soap message being sent in.

SoapSenderA SoapSender is a class that inherits from the abstract SoapPort class. This class basically corresponds to a Filter that allows you modify the input of the Soap Message and the output of the message. This base class allows you to control the sending and receiving of the soap message. To use the SoapSender class, create an instance of this class and set its Destination property (an Uri) either through its constructor or setting its property explicitly. Next, call the Send or BeginSend methods to Synchronously and Asynchronously respectively, send a SoapEnvelope class to the Destination.

Source Code ExplanationThe Demo application is separated into two separate projects. A Publisher Windows Application that hosts the Publisher Service, and the Client Subscription Application that hosts the Client Subscription Response Service.

The Publisher Application is broken up into two pieces. A Publisher Windows .NET application, and a Publisher Class. The Publisher Application is a basic windows forms application that displays subscribers through a listbox in real time subscribing to the Publisher, and unsubscribing from the Publisher. It also contains a Textbox that gives the Publisher the ability to publish an article or data to all the listed subscribers. When the Publisher clicks on the Publish Article button, a file is created on the server, and then a copy of its contents is sent to all the subscribers.

The publisher Class is a custom class that inherits from the SoapReceiver Class. It overrides the Receive method and checks for a Soap Action on the SoapEnvelope. It parses the SoapAction to determine if the message being sent in is a Subscription Request, or a Unsubscription request. Also, while the Publisher application continues to run, if the Publisher decides to publish an article, it is then sent using a SoapSender to all the listening Subscribers.

Publisher Code:using System;using Microsoft.Web.Services2;using Microsoft.Web.Services2.Messaging;using Microsoft.Web.Services2.Addressing;using System.Web.Services.Protocols;using System.Xml;using System.Collections;using System.IO;using System.Collections.Specialized;

+ folderWatch

+ + +

); } fsw.Filter = +

urn:ArticlePublisherApp:Publisher, Name, ID); Action act =

'urn:ArticlePublisherApp:Publisher +

Action act = envelope.Context.Addressing.Action; , subscriberName = envelope.SelectSingleNode ( foreach(object o in _subscribers) { DictionaryEntry de = (DictionaryEntry)o; Subscriber s = (Subscriber)_subscribers[de.Key]; SoapEnvelope responseMsg = responseMsg.Context.Addressing.From =

'urn:ArticlePublisherApp:Publisher

+ strContents + SoapSender msgSender = , s.Name, s.ID, s.ReplyTo.ToString())); }

Client Subscriber The Client Subscriber application is also broken up into two pieces: A client Subscriber Windows .NET application, and a Subscriber Class. The Client Subscriber application is a basic windows forms application that contains a MainMenu, and a StatusBar, along with a ReadOnly Textbox. The MainMenu has a MenuItem that has the ability to Send a Subscription request to the Publisher, along with a Unsubscription Request to stop subscribing to the Publisher. The StatusBar displays the Register ID of the Client when registered. The ReadOnly Textbox displays any article that is published from the Publisher, at any given time the Publisher decides to publish the article/data. The Subscriber Class is a custom class that inherits from the SoapReceiver class. It overrides the Receive method and checks for a SoapAction Header on the SoapEnvelope. It parses the SoapAction to determine if the message being sent back from the Publisher is a simple response to the subscription or unsubscription request, or a notify message to let the Subscriber Form know that an article is being sent from the Publisher. To really test the applicaiton out, start multiple instances of the Client Subscription Application.

Subscriber Class Code: using Microsoft.Web.Services2.Messaging;using Microsoft.Web.Services2.Addressing;using System.Web.Services.Protocols;using System.Xml;,

Happy Coding!

If you like this SOA tune… Stay tuned for BizTalk Server 2004 Articles as well!!!

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有