HomeDigital EditionSys-Con RadioSearch Web Services Cd
B2B Beginning WS Business Process Management Case Studies Content Management Distributing Computing e-Business Electronic Data Interchange Enterprise Industry Insight Integration Interviews Java & Web Services .NET Portal Product Reviews Scalability & Performance Security SOAP Source Code UDDI Wireless WS Standards WS Tips & Techniques WSDL WS Editorials XML

Beyond Point to Point by Adam Blum
WSJ Vol 04 Issue 04 - pg.55



Listing 1

<s12:Envelope
  xmlns:12'http://www.w3.org/2003/05/soap-envelope'
  xmlns:wsa='http://schemas.xmlsoap.org/ws/2003/03/addressing'
    xmlns:wse='http:// schemas.xmlsoap.org/ws/2004/01/eventing'
    xmlns:eri='http://electronicsretailer.com/inventory'>
    <s12:Header>
      <wsa:Action>
         http://schemas.xmlsoap.org/ws/2004/01/eventing/Subscribe
      </wsa:Action>
      <wsa:To>http://electronicsretailer.com/CBRService</wsa:To>
      <wsa:ReplyTo>
         <wsa:Address>
            http://electronicsretailer.com/inventory
         </wsa:Address>
      </wsa:ReplyTo>
      <wsa:MessageID>
        uuid:d7c5276b-de29-4313-b4d4-b3425b200840
      </wsa:MessageID>
    </s12:Header>
    <s12:Body>
       <wse:Subscribe>
          <wse:NotifyTo>
            <wse:Address>
http://electronicsretailer.com/inventory/HandleNewProduct.asp
            </wse:Address>
            <wsa:ReferenceProperties>
               <eri:LocalSubscriptionID>1234</eri:LocalSubscriptionID>
            </wsa:ReferenceProperties>
          <wse:NotifyTo>
          <wse:Filter xmlns:er='http://electronicsretailer.com/schemas'>
            /s12:Envelope/s12:Body/er:NewProduct
          </wse:Filter>
       </wse:Subscribe>
    </s12:Body>
</s12:Envelope>

Listing 2

<s12:Envelope
    xmlns:12'http://www.w3.org/2003/05/soap-envelope'
    xmlns:wsa='http://schemas.xmlsoap.org/ws/2003/03/addressing'
    xmlns:wse='http:// schemas.xmlsoap.org/ws/2004/01/eventing'
    xmlns:eri='http://electronicsretailer.com/inventory'>
   <s12:Header>
      <wsa:Action>
       http://schemas.xmlsoap.org/ws/2004/01/eventing/SubscribeResponse
      </wsa:Action>
      <wsa:To>http://electronicsretailer.com/inventory</wsa:To>
      <wsa:RelatesTo>
        uuid:d7c5276b-de29-4313-b4d4-b3425b200840
      </wsa:RelatesTo>
    </s12:Header>
    <s12:Body>
       <wse:SubscribeResponse>
           <wse:Id>uuid:5005cfe6-c2c6-4296-9c3a-80b9ad111813</wse:Id>
           <wse:Expires>2004-03-01T00:00:00-000-00:00</wse:Expires>
       </wse:SubscribeResponse>
    </s12:Body>
</s12:Envelope>

Listing 3

<s12:Envelope
    xmlns:12'http://www.w3.org/2003/05/soap-envelope'
    xmlns:wsa='http://schemas.xmlsoap.org/ws/2003/03/addressing'
    xmlns:wse='http://schemas.xmlsoap.org/ws/2004/01/eventing'
    xmlns:eri='http://electronicsretailer.com/inventory'
    xmlns:er='http://electronicsretailer.com/schemas'>
    <s12:Header>
      <wsa:Action>
       http://electronicsretailer.com/schemas/NewProduct
      </wsa:Action>
      <wsa:To>http://electronicsretailer.com/inventory</wsa:To>
      <eri:LocalSubscriptionID>1234</eri:LocalSubscriptionID>
    </s12:Header>
    <s12:Body>
       <eri:NewProduct>
          <eri:ProductID>AC-MP471</eri:ProductID>
          <eri:ProductName>
              Acme 128MB Portable MP3 Player
          </eri:ProductName>
          <eri:ProductCategory>MP3 Players</eri:ProductCategory>
          <eri:Price>47.56</eri:Price>
       </eri:NewProduct>
    </s12:Body>
</s12:Envelope>

Listing 4: CBRSubscribe.cs

//	CBRSubscribe
//
// This is a command line tool that can be used to subscribe
// and endpoint for notifications from a WS-Eventing based Content-Based Routing
service
//
//  Usage: CBRSubscribe <web service for notifications> <filter expression>
 [CBR URL]
//
//  - the first argument is the address of the endpoint where WS-Eventing
notifications
//      (documents matching subscription criteria) should be sent
//  - the second argument is the filter expression used for the subscription
//  - the third argument is the URL for the content-based routing service itself
//
//  For convenience this has been packaged as a standalone command line tool.
//  However, most likely you would use the Subscribe function alone in your own C#
//  or other .NET programs.

using System;
namespace CBRSubscribe
{
class MainClass
	{
		[STAThread]
		///////////////////////////
/// Main - Acts as simple shell to grab command line arguments
		static void Main(string[] args)
		{
			if (args.Length<3)
			{
	Console.WriteLine("Usage: CBRSubscribe <web service for
	notifications> <filter expression> <CBR URL>");
	return;
			}
			bool result;
			result=Subscribe(args[0],args[1],args[2]);
			if (result)
	Console.WriteLine("Endpoint {0} is successfully subscribed to
	documents matching {1} with CBR service
	{2}!",args[0],args[1],args[2]);
			else
				Console.WriteLine("Subscription failed!");

			return;
		}

/// Subscribe function that does the actual work
/// <param name="notifyAddress">
/// this is the address of the endpoint where notifications should be sent
/// </param>
/// <param name="subscriptionFilter">
/// the XPath expression used to identify the documents of interest
/// </param>
/// <param name="cbrServiceURL">
/// The URL where the Content-Based Routing service is located.
/// </param>
/// <returns>boolean to indicate success or failure</returns>
static bool Subscribe(string notifyAddress,string subscriptionFilter,string
cbrServiceURL)
		{
	CBRSubscribe.CBRService.Subscribe subscription=new
	CBRSubscribe.CBRService.Subscribe();
	subscription.NotifyTo=new
	CBRSubscribe.CBRService.EndpointReferenceType();
	subscription.NotifyTo.Address=new
	CBRSubscribe.CBRService.AttributedURI();
	subscription.NotifyTo.Address.Value=notifyAddress;
	subscription.Filter=new
	CBRSubscribe.CBRService.MessagePredicateAssertion();
	subscription.Filter.Value=subscriptionFilter;

	CBRSubscribe.CBRService.Eventing objEventing=new
	CBRSubscribe.CBRService.Eventing(cbrServiceURL);
	CBRSubscribe.CBRService.SubscribeResponse subscribeResponse=new
	CBRSubscribe.CBRService.SubscribeResponse();
	subscribeResponse=objEventing.SubscribeOp(subscription);

			// sanity check the subscription results
			bool result=true;
			if (!subscribeResponse.Id.StartsWith("uuid:"))
				result=false;

			return result;
		}
	}
}