Connected Thoughts – Thiago Almeida

August 9, 2009

Sending XML messages to BizTalk using the WCF Channel Model

Filed under: BizTalk — Thiago Almeida @ 4:06 pm

It is quite a common requirement to have a generic receive location in BizTalk to accept any XML file. Richard Seroter has listed a few options already on how to do this.

I looked into how BizTalk exposes its WCF receive locations and how they could be consumed by using the WCF channel model, without having to use WSDLs or proxy classes.

Creating the BizTalk Receive Location

In my scenario I created a one way BizTalk receive port, and a receive location with the WCF.NetTcp adapter and the XMLReceive pipeline (but you could choose other WCF adapters here):

image

I then configured the WCF-NetTcp adapter properties by entering a URI and changing the security mode to None (for simplicity sake):

image image

 

The WCF Adapter Interfaces

The main part of the BizTalk WCF receive locations is in Microsoft.BizTalk.Adapter.Wcf.Runtime.dll found on the installation folder  of BizTalk 2006 R2 and 2009.

As already noted by Paolo Salvatori “the WCF Receive Adapter instantiates a singleton instance of the BizTalkServiceInstance class for each WCF Receive Location”. The BizTalkServiceInstance class declaration implements the following service contract interfaces:

·         ITwoWayAsync
·         ITwoWayAsyncVoid
·         IOneWayAsync
·         IOneWayAsyncTxn
·         ITwoWayAsyncVoidTxn

 

Each of these cover the different scenarios of the WCF receive locations. They all have a BizTalkSubmit method, but if you inspect the BizTalkServiceInstance class’ implementation of this method (for all of the interfaces) you’ll notice that it’ll throw a NotSupportedException exception, so you can’t use this method to submit messages to the BizTalkServiceInstance instance. Read up Paolo’s post for some more information. Here’s the BizTalkSubmit implementation for the ITwoWayAsynchVoid for example:

[OperationBehavior]
void ITwoWayAsyncVoid.BizTalkSubmit(Message message)
{
   throw new NotSupportedException();
}

What is made available to us though is the server side IAsyncResult model. This model is well explained in this blog post by Dan Rigsby . The methods to use to send messages to BizTalk WCF receive locations are the other two method of BizTalkServiceInstance that implement the IAsyncResult mode class: BeginTwoWayMethod (or BeginOneWayMethod for the IOneWay… interfaces) and EndTwoWayMethod (or EndOneWayMethod).

 

Sending Messages to the Receive Location

Now that we have a BizTalk receive location and a basic understanding of the WCF receive adapters we can move on to sending a message to it from our .NET code. First add a reference to System.ServiceModel.dll and System.Runtime.Serialization.dll. Our one way receive location uses the ITwoWayAsyncVoid interface (the IOneWay… interfaces are only for the WCF-NetMsmq adapter, and the ones ending in Tx are for when transactions are enabled on the receive location. Interfaces without Void are for receive response):

namespace Microsoft.BizTalk.Adapter.Wcf.Runtime
{
[ServiceContract(Namespace = "http://www.microsoft.com/biztalk/2006/r2/wcf-adapter")]
public interface ITwoWayAsyncVoid
{
    // Methods
    [OperationContract(AsyncPattern = true, IsOneWay = false, Action = "*", ReplyAction = "*")]
    IAsyncResult BeginTwoWayMethod(Message message, AsyncCallback callback, object state);
    [OperationContract(IsOneWay = false, Action = "BizTalkSubmit")]
    void BizTalkSubmit(Message message);
    void EndTwoWayMethod(IAsyncResult result);
}
}

You can get the other service contracts from Paolo’s post or from Microsoft.BizTalk.Adapter.Wcf.Runtime.dll.

Once you have the appropriate service contract interface in your code you can now configure the end point. I added mine to my app’s App.Config file with the address configured on the BizTalk WCF receive location and a binding that follows the one configured there:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_ITwoWayAsyncVoid">
          <security mode ="None" />
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint
        address="net.tcp://bt09standalone.thiago.com/WCFNetTcpGenericReceive"
        binding="netTcpBinding"
        bindingConfiguration="NetTcpBinding_ITwoWayAsyncVoid"
        contract="Microsoft.BizTalk.Adapter.Wcf.Runtime.ITwoWayAsyncVoid"
        name="BlogWCFGenericReceiver" />
    </client>
  </system.serviceModel>
</configuration>

Here is the BeginTwoWayMethod method declaration for the ITwoWayAsyncVoid interface:

[OperationBehavior]
IAsyncResult ITwoWayAsyncVoid.BeginTwoWayMethod(Message message, AsyncCallback callback, object state);

You pass it a WCF message, and can also pass an async callback method so that the main thread isn’t blocked. You can also pass in an object in the state parameter and you will get the same object back once the callback method is called.

Alternatively from passing in a callback method you can just tell the wait handle to block the current thread until a signal is received – once it is received this is when BizTalk is ready for you to call the EndTwoWayMethod.

Here is the method in my windows forms app that sends a message to BizTalk and uses the wait handle to wait for a signal:

private void btnSubmitWaitHandle_Click(object sender, EventArgs e)
{

    txtResults.Text += DateTime.Now.TimeOfDay.ToString()
                         + " Sending message to BizTalk\r\n";
    DisableForm();

    try
    {
        cf = new ChannelFactory<ITwoWayAsyncVoid>("BlogWCFGenericReceiver");
        cf.Open();
        ITwoWayAsyncVoid waitHandleProxy = cf.CreateChannel();

        btnSubmitWaitHandle.Enabled = false;

        Channels.Message msg =
            Channels.Message.CreateMessage(Channels.MessageVersion.Default,
            "BeginTwoWayMethod", new XmlTextReader(new StringReader(txtMessage.Text)));

        //Start the call to BizTalk and get the async result back
        IAsyncResult res = waitHandleProxy.BeginTwoWayMethod(msg, null, null);

        //Blocks current thread until until AsyncWaitHandle receives a signal
        res.AsyncWaitHandle.WaitOne();

        //End the call once the wait handle signal is received from BizTalk
        waitHandleProxy.EndTwoWayMethod(res);

        txtResults.Text += DateTime.Now.TimeOfDay.ToString() +
            " Message sent successfully\r\n";
        cf.Close();
    }
    catch (Exception ex)
    {
        txtResults.Text += DateTime.Now.TimeOfDay.ToString()
          + " Exception: " + ex.Message + "\r\n";
        if (cf != null) { cf.Abort(); }

    }
    finally
    {
        EnableForm();
        if (cf.State == CommunicationState.Opened)
        { cf.Close(); }
    }
}

And here are the two methods that send a message to BizTalk using the callback approach:

private void btnSubmitAsyncCallback_Click(object sender, EventArgs e)
{
    cf = new ChannelFactory<ITwoWayAsyncVoid>("BlogWCFGenericReceiver");
    cf.Open();
    asyncCallbackProxy = cf.CreateChannel();
    string state = Guid.NewGuid().ToString();
    txtResults.Text += DateTime.Now.TimeOfDay.ToString()
                         + " Message " + state + " sent to BizTalk\r\n";

    //Create message
    Channels.Message msg =
        Channels.Message.CreateMessage(Channels.MessageVersion.Default,
        "BeginTwoWayMethod", new XmlTextReader(new StringReader(txtMessage.Text)));

    //Start the call to BizTalk and pass in the async callback method
    DisableForm();
    IAsyncResult res = asyncCallbackProxy.BeginTwoWayMethod(
       msg, new System.AsyncCallback(OnEndTwoWayMethod), state);
}

public void OnEndTwoWayMethod(IAsyncResult asyncResult)
{
    //Get the guid back, this will be what we passed as 'state' on BeginTwoWayMethod
    string msgid = asyncResult.AsyncState.ToString();
    try
    {
        //End the call to BizTalk. Make sure it's the same asyncCallbackProxy
        //object instance used to send the message otherwise it will fail
        asyncCallbackProxy.EndTwoWayMethod(asyncResult);

        this.Invoke(new MethodInvoker(delegate()
            { txtResults.Text += DateTime.Now.TimeOfDay.ToString() +
                " Message " + msgid + " sent successfully\r\n"; }));
    }
    catch (Exception ex)
    {
        this.Invoke(new MethodInvoker(delegate()
            { txtResults.Text += DateTime.Now.TimeOfDay.ToString()
                + "Message: "
                + msgid + ". Exception: " + ex.Message + "\r\n"; }));
        if (cf != null) { cf.Abort(); }
    }
    finally
    {
        this.Invoke(new MethodInvoker(delegate()
        { EnableForm(); }));
        if (cf.State == CommunicationState.Opened)
        { cf.Close(); }
    }
}

That’s it! We can now send any XML message to BizTalk this way. Here’s what my tester application looks like after two messages were sent with the WaitHandle and once with the callback approach:

image

If the BizTalk receive location is disabled or the BizTalk host is stopped, you get a System.ServiceModel.EndpointNotFoundException exception when calling the EndTwoWayMethod method (I removed my machine’s ip address from the exception):

“Could not connect to net.tcp://bt09standalone.thiago.com/WCFNetTcpGenericReceive. The connection attempt lasted for a time span of 00:00:02.0141069. TCP error code 10061: No connection could be made because the target machine actively refused it ip address:808.”

What if, for example, we change the Inbound BizTalk message body from Body to Path and enter an invalid path?

If you have ‘Include exception detail in faults’ enabled you get an exception of type  System.ServiceModel.FaultException<System.ServiceModel.ExceptionDetail> with the right details:

“Unable to find match for inbound body path expression "/nothing" in message.”

If the tickbox is not enabled you get a System.ServiceModel.FaultException:

“The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.”

If you untick the ‘Suspend request message on failure’ and there is an exception in the pipeline, the message doesn’t get suspended and the client gets the error back when ‘Include exception detail in faults’ is ticked:

“There was a failure executing the receive pipeline: "Microsoft.BizTalk.DefaultPipelines.XMLReceive, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Source: "XML disassembler" Receive Port: "Blog.GenericReceive" URI: "net.tcp://localhost/WCFNetTcpGenericReceive" Reason: Finding the document specification by message type "http://Blog.GenericReceiver.BT/Schemas#aGenericReceiverSample" failed. Verify the schema deployed properly. ”

So there you have it, another way of submitting any XML messages to BizTalk by using the WCF channel model.

 

Download the sample code

 

Regards,

Thiago Almeida

August 7, 2009

Issue 7 of BizTalk HotRod Magazine is out

Filed under: BizTalk — Thiago Almeida @ 8:56 am

Just saw on Rahul’s blog that the latest edition of the BIzTalk HotRod magazine is out, with some great articles on:

  • Azure
  • Testing maps and schemas
  • Richard Seroter’s "SOA Patterns With BizTalk Server 2009" book review
  • Throwing typed faults from orchestrations exposed as a WCF service
  • Integrating BizTalk with Dynamics AX
  • Managing BizTalk with WMI and C#
  • BizTalk resources list

Download it here!

July 31, 2009

BizTalk Server 2009 RFID Operations Guide Released

Filed under: BizTalk — Thiago Almeida @ 11:42 am

 

The BizTalk Server 2009 RFID Operations Guide has hit the streets!

The BizTalk 2009 Operations Guide was made available last week, and yesterday Microsoft have also released its RFID counterpart, with 108 pages worth of BizTalk RFID goodness, with best practices and input from the best in the field. It has four main sections: Planning the Environment, Operations Checklist, Managing Deployment, and Useful Links.

Online version:

http://msdn.microsoft.com/en-us/library/ee309289(BTS.10).aspx

Downloadable version:

http://go.microsoft.com/fwlink/?LinkId=158724

 

You can also read more about it on Ewan Fairweather’s blog.

Regards,

Thiago Almeida

July 29, 2009

Auckland Connected Systems User Group Meeting 16 August – Getting Your Head In The Cloud

Filed under: BizTalk — Thiago Almeida @ 6:03 pm

ACSUGLogoTitle

The next ACSUG meeting is set for the 12th of August at 6:00pm at Datacom, 210 Federal Street downtown Auckland. Register here.

Presentation:

The introduction of cloud computing marks a significant change in the IT industry. Offering scalability, flexibility, efficiency and lower costs, the benefits of this technology are widespread and generating a lot of attention from CIO’s, architects and technology leaders as businesses and government look to leverage ‘the Cloud’ within their organisations.

Software plus Services (S+S) is Microsoft’s vision for the connected world. When you combine the ever growing power of devices and the increasing ubiquity of the Web, you come up with a sum that is greater than its parts. The best of installed software and online services.

Is this technology for you? Make up your own mind when you understand the what, why, where, when and how of cloud computing.

Key learning points:

1. Cloud computing is a hot topic right now, discover exactly what it is and why you should be interested.

2. What does it mean for IT in NZ (government, enterprise, small business etc.)?

3. A look at the Windows Azure offering and other Online Services from Microsoft.

Presenter:

Scott Wylie leads the Developer and Platform Strategy Group at Microsoft in New Zealand which means working with the DPE team to excite customers and communities about Microsoft’s new and emerging technologies. He was previously the NZ practice manager for Microsoft Services. Prior to Microsoft he worked in Australia, the UK and the US in a variety of ISV and corporate environments – having started his career in the early 80’s as an IBM 370 assembler programmer! After hours he can be found playing with his band ‘President Gas’ and spending time with his family.

Register here to attend. Free entry, pizza and drinks provided.

Regards,

Thiago Almeida

July 28, 2009

BizTalk 2009 ISV Editions

Filed under: BizTalk — Thiago Almeida @ 11:18 am

As you might know Microsoft have recently revealed two new BizTalk 2009 editions for Independent Software Vendors (ISVs). Here are more details about them from the Microsoft World Wide Partner Conference 2009 two weeks ago (July 13th 2009):

ENTERPRISE RUNTIME EDITION

  • Only used with of unified ISV solution
  • Unlimited CPUs, limited to 5 BizTalk applications
  • Includes all capabilities, adapters and accelerators
  • Supports scale out/failover, multi-server configuration with multiple message boxes

STANDARD RUNTIME EDITION

  • Only used to embed into ISV application and interoperate with up to 2 additional external systems
  • Includes all capabilities, adapters and accelerators
  • Limited to 2 CPUs on single server and 1 BizTalk Applications
  • Single server with single message box, no failover

These two new editions add to the existing six editions: Enterprise Edition, Standard Edition, Branch Edition, Developer Edition, RFID Enterprise, and the BizTalk Adapter Pack.

The BizTalk editions page hasn’t been updated yet and the pricing hasn’t been revealed for the two new ones but information should be out soon.

Regards,

Thiago Almeida

July 27, 2009

BizTalk 2009 – Deploying Orchestration Project Throws EnvDTE FileLoadException (and other issues)

Filed under: BizTalk — Thiago Almeida @ 6:16 pm

We have a few BizTalk 2009 projects going on at the moment and are running into some issues. The latest is the that when deploying a project containing an orchestration from Visual Studio 2008 you see an exception similar to:

“xlang/s engine event log entry: FileLoadException exception occurred while the XLANG/s runtime enlisted a service.
Error message:Could not load file or assembly ‘EnvDTE, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0×80131040)”

The problem here seems to be that the orchestration was deleted from BizTalk (usually through the Administration Console), but the Redeploy property of the BizTalk project in Visual Studio is set to True. Once you set the Redeploy property of the project to False it will deploy fine.

Eliasen has posted about the other issues that we have been noticing, mostly between BizTalk 2009 and Visual Studio 2008:

http://blog.eliasen.dk/2009/07/21/IssuesWithBizTalk2009OnVSNET2008.aspx

Some of these we have reported to Microsoft already so I’ll post back when that gets some traction.

Update 17 November 2009: There is a hotfix coming up that fixes most if not all of these issues, keep tuned and I will update this post when it is released (either separately or as a service pack for BizTalk 2009).

 

Regards,

Thiago Almeida

July 16, 2009

BizTalk 2009 Performance Slides release by Microsoft BizTalk CAT Team

Filed under: BizTalk — Thiago Almeida @ 9:26 am

Just saw on Ewan Fairweather’s blog that the BizTalk Server Customer Advisory Team have released four presentation slides about BizTalk Server 2009 performance. The presentations will give you a great insight into how the team sets up performance labs for the BizTalk projects they’re involved in, and have many many performance tips, links to online resources, and tools to use. The presentations even have actual BizTalk CAT team customer scenario details (Skandia internet banking solution).

Check ou Ewan’s blog post for the links:

http://blogs.msdn.com/ewanf/archive/2009/07/15/biztalk-cat-page-on-msdn-and-presentation-resources.aspx

If you are interested in the wonderful world of BizTalk performance I recommend you also watch the videos of Paolo Salvatori’s presentation at the Sweden BizTalk user group:

Video: BizTalk 2009 – End to end performance testing (1/2)

Video: BizTalk 2009 – End to end performance testing (2/2)

Regards,

Thiago Almeida

July 9, 2009

Auckland Connected Systems User Group – Introduction to the WCF-SQL Adapter with Thiago Almeida

Filed under: BizTalk — Thiago Almeida @ 11:44 am

ACSUGLogoTitle

In this session Thiago introduces the new WCF based SQL Server adapter that is part of the BizTalk Adapter Pack 2.0. Learn the architecture behind the adapter, and how to use the SQL Adapter from BizTalk, or directly from .NET applications via the WCF service and channel models.

Register to attend

Free drinks and pizza provided!

Where:
Datacom Systems Limited, 210 Federal Street, Auckland CBD, Auckland, 1141
Map (parking on the street outside Datacom. There is also pay parking in Hobson St parallel to the venue)

When: 16 July 2009 at 6:00:00 p.m.

Please register if you are attending, and forward the meeting details to those who might be interested.

For a recording with the same presentation see the video on www.cloudcast.net

July 7, 2009

BizTalk Light And Easy Viewing Series – WCF SQL Adapter presentation available

Filed under: BizTalk — Thiago Almeida @ 9:25 am

My webcast on the new WCF SQL Adapter has been made available on CloudCasts, a great initiative started by Alan Smith. Clout TV is a community based website for hosting webcasts relating to Microsoft technologies.

Here’s the link to the presentation:

http://www.cloudcasts.net/ViewWebcast.aspx?webcastid=2521554268962766719

There are several other webcasts on the site already, including two others by Kent Weare that are part of the BizTalk Light And Easy Viewing Series.  Make sure to check them out!

Mick Badran asked many BizTalk/CSD MVPs and Industry experts (around the globe) to share their knowledge and expertise. We came up with a series of Webcasts/Presentations and Demo Code for the community around many aspects of BizTalk 2009 – from new features in BAM, SharePoint, SQL Adapter… to Orchestration Performance. Some of them are being finalized and they will all be made available soon.

July 4, 2009

Microsoft MVP in BizTalk

Filed under: BizTalk — Thiago Almeida @ 11:37 am

A few days ago I received an overnight email from Microsoft presenting me with an MVP award in BizTalk. Needless to say I am very excited and happy about it! It is not often that this kind of news is blogged about by one of the best in the field before you do.

I’m really looking forward to working a bit closer with other MVPs, which include many experts whom I look up to, and the product team. I will strive to improve my commitment to the BizTalk and Connected Systems community.
Thank you to all the Microsoft employees, other fellow MVPs (so good to say that), and members of the community that made this happen, and to all that have congratulated me.

MVP_FullColor_ForScreen

Regards,
Thiago Almeida

« Newer PostsOlder Posts »

Blog at WordPress.com.