ESB Guidance...part 7

Listen with webReader
Published 06 February 08 10:26 PM | wmmihaa
How to consume an Itinerary Service

I have to admit; -I wasn’t planning on writing seven articles about ESB Guidance. But the documentation does not cover much of this topic, and there are things to take under consideration when working with the itinerary services provided by the ESB Guidance.

Normally when working with Web Services, we are given a URL, which we’ll reference in our Visual Studio project. Adding this reference will give us a proxy class, along with other classes needed to submit the service methods.  For example if the service would have a SubmitOrder(Order order) method, we’d have an Order class to work with.

ESB Guidance comes with both a Web Service and a WCF Service Itinerary On-Ramps. Both versions support One-way- and Two-way messaging scenarios.

Calling an Itinerary Service is a bit different from calling a Web- or WCF Service in a normal fashion. This is because the service methods are not typed to any request or response object.  Each itinerary service method can serve any type of itinerary, which is the actual definition of what the service will do. In other word, part from many practical reasons, it is possible to have only one receive location and one subscribing send port, to serve as all endpoints of your BizTalk solution (please do not read this as an recommendation). For more information about how Itineraries work, see previous post.

So being a consumer of an Itinerary Service, clearly, given a URL is not enough. We also need the schema definitions along with the actual itinerary (xml file).

If you are comfortable with creating the xml message in your code, all you need to do is to add the service reference to your project, create your xml message according to the schema, deserialize the itinerary xml to the Itinerary object and call the service:

static void Sample1()
{
    // Create the Order xml. This is the "object" that is going to be submitted.
    XmlDocument orderXml = new XmlDocument();
    orderXml.Load(@"C:\ESB Guidance\Data\NAOrderDoc.xml");
    
    // Create the Itinerary Xml Document from the file 
    XmlDocument itinararyXml = new XmlDocument();
    itinararyXml.Load(@"C:\ESB Guidance\Itineraries\SubmitOrderItinerary.xml");

    // Calling the WCF Service
    using (ProcessRequestClient wcfClient = 
        new ProcessRequestClient("WSHttpBinding_ITwoWayAsyncVoid"))
    {
        if (wcfClient.State != System.ServiceModel.CommunicationState.Opened)
            wcfClient.Open();

        // Creating the Itinerary
        // Deserialize the OuterXml to the Itinerary object
        StringReader reader = new StringReader(itinararyXml.DocumentElement.OuterXml);
        XmlSerializer ser = new XmlSerializer(typeof(Itinerary), 
            "http://schemas.microsoft.biztalk.practices.esb.com/itinerary");
        Itinerary wcfItinerary = 
            (Itinerary)ser.Deserialize(reader);

        // Submit WCF Call
        wcfClient.SubmitRequest(wcfItinerary, orderXml.OuterXml);
        wcfClient.Close();
    }

    
    // Same as above but calling the Web Service
    using (asmxItineraryOneWay.Process svc = 
        new asmxItineraryOneWay.Process())
    {
        svc.Credentials = System.Net.CredentialCache.DefaultCredentials;

        // Creating the Itinerary
        // Deserialize the OuterXml to the Itinerary object
        StringReader reader = new StringReader(itinararyXml.DocumentElement.OuterXml);
        XmlSerializer ser = new XmlSerializer(typeof(asmxItineraryOneWay.Itinerary), 
            "http://schemas.microsoft.biztalk.practices.esb.com/itinerary");
        asmxItineraryOneWay.Itinerary asmxItinerary = 
            (asmxItineraryOneWay.Itinerary)ser.Deserialize(reader);

        // Set the ItineraryValue
        svc.ItineraryValue = asmxItinerary;

        XmlNode orderXmlNode = (XmlNode)orderXml;
        svc.SubmitRequest(orderXmlNode);
    }

}

However, you could use Xsd.exe or XsdObjectGen.exe to create the Order class, to submit to the service method. I also created a sample ItineraryFactory class to help deserialize the Itinerary and to serialize the Order object:

static void Sample2()
{
    // Create the Order object.
    OrderDoc order = new OrderDoc();
    order.customerName = "Microsoft";
    order.ID = 1;
    order.requestType = 10;

    // Create the Itinerary
    string itineraryXml = @"C:\ESB Guidance\Itineraries\SubmitOrderItinerary.xml";
    Itinerary itinerary = ItinaryFactory.Load(itineraryXml);

    // Serialize the Order object to string
    string data = ItinaryFactory.SerializeToString(order);
    
    using (ProcessRequestClient client = new ProcessRequestClient("WSHttpBinding_ITwoWayAsyncVoid"))
    {
        if (client.State != System.ServiceModel.CommunicationState.Opened)
            client.Open();
        client.SubmitRequest(itinerary, data);
        client.Close();
    }
}

Comments

# Jim Bowyer said on February 26, 2008 03:48 AM:

Great stuff Mikael!  Have you ever tried this approach calling two-way services (like soap/WCF), instead of one as in your example?  This is a variation I can't seem to get to work...   Thx, JB

# wmmihaa said on February 29, 2008 11:28 PM:

It works for me, but I did have a problem with the wcf on-ramp before. Have you tried using the WS ports instead.

Maybe if you give me some more information, I could help you out.

Sorry I didn't answer earlier...

# John said on April 8, 2008 07:58 PM:

Great site and useful content! Could you leave some opinion about my sites?

<a href="My' target=_new rel=nofollow mce_href='http://ownsite.com/h/">My'>ownsite.com/.../">My pages</a>

[url=http://ownsite.com/b/]My pages[/url]

http://ownsite.com/p/ My pages

# Cosmas Kange said on October 13, 2009 06:17 AM:

Thanks for the samples - Mikael.

I am just getting into the ESB bandwagon (Toolkit 2.0) and found your samples helpful.

It however appears there are API changes with the new Toolkit so I can only get the samples working by generating .asmx proxies. The WCF proxies appear to be missing the 'Itinerary Type - Class' but perhaps there is a Wrapper Class to make this work. Could you please shed some light on this - possiby update your code for the new Toolkit? The documentation appears to be lacking.

Thank you for your time.

Cosmas Kange  

# prabhjot said on May 1, 2010 02:24 PM:

yes cosmas you are correct this code does not work with wcf proxies ( esb tool kit 2.0) the "itinerary class " is missing and it ask for some itinerary defination class ... i am not able to crack it as yet... still trying

prabhjot

Leave a Comment

(required) 
(required) 
(optional)
(required) 

This Blog

News

    MVP - Microsoft Most Valuable Professional BizTalk User Group Sweden BizTalk blogdoc

    Follow me on Twitter Meet me at TechEd

    Visitors

    Locations of visitors to this page

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Syndication