Windows 7 Phone Development and Hyper-V/Server 2008

Hi,

For those of you that want to develop Windows Phone apps on Hyper-V or Windows Server 2008, think again!!! You have been warned:

 

1. Intel I7 VPRO processor with Hyper Threading enabled causes blue screens with Hyper-V

a. Solution: Disable Hyper Hyper Threading

2. Windows 7 Phone Development Tool kit and Hyper-V will not work, the emulator will crash the VM, once it starts

a. Solution: Throw a Tantrum, kick, swear, run around and throw your clothes off and then install it on a non VM OS, oh wait another problem!!!

3. Windows 7 Phone tools do not work on Windows Server 2008

a. You need a host operating system like Windows 7/Vista

Boot VHD Drive in Windows Server 2008 R2

Hi,

 

You can configure the Windows Boot Loader using BCDEDIT to boot off a VHD drive from the boot menu:

 

C:\Windows\system32>bcdedit /copy {current} /d "Windows 7 VHD"

Copy the output of the GUID and use it here:

my example is: db994f45-acc9-11df-a9e1-e4856d34cfae

 

Do not use my GUID!

C:\Windows\system32>bcdedit /set {db994f45-acc9-11df-a9e1-e4856d34cfae} device v
hd=”[H:]\Windows 7 Development\Windows 7 Development.vhd”
The operation completed successfully.

C:\Windows\system32>bcdedit /set {db994f45-acc9-11df-a9e1-e4856d34cfae} osdevice vhd=”[H:]\Windows 7 Development\Windows 7 Development.vhd”
The operation completed successfully.

C:\Windows\system32>bcdedit /set {db994f45-acc9-11df-a9e1-e4856d34cfae} detecthal on
The operation completed successfully.

Then double check config:

 

C:\Windows\system32>bcdedit

Windows Boot Manager
——————–
identifier              {bootmgr}
device                  partition=\Device\HarddiskVolume1
description             Windows Boot Manager
locale                  en-US
inherit                 {globalsettings}
default                 {current}
resumeobject            {db994f41-acc9-11df-a9e1-e4856d34cfae}
displayorder            {current}
                        {db994f45-acc9-11df-a9e1-e4856d34cfae}
toolsdisplayorder       {memdiag}
timeout                 30

Windows Boot Loader
——————-
identifier              {current}
device                  partition=C:
path                    \Windows\system32\winload.exe
description             Windows Server 2008 R2
locale                  en-US
inherit                 {bootloadersettings}
recoverysequence        {db994f43-acc9-11df-a9e1-e4856d34cfae}
recoveryenabled         Yes
osdevice                partition=C:
systemroot              \Windows
resumeobject            {db994f41-acc9-11df-a9e1-e4856d34cfae}
nx                      OptOut
hypervisorlaunchtype    Auto

Windows Boot Loader
——————-
identifier              {db994f45-acc9-11df-a9e1-e4856d34cfae}
device                  vhd=[H:]\Windows 7 Development\Windows 7 Development.vhd

path                    \Windows\system32\winload.exe
description             Windows 7 VHD
locale                  en-US
inherit                 {bootloadersettings}
recoverysequence        {db994f43-acc9-11df-a9e1-e4856d34cfae}
recoveryenabled         Yes
osdevice                vhd=[H:]\Windows 7 Development\Windows 7 Development.vhd

systemroot              \Windows
resumeobject            {db994f41-acc9-11df-a9e1-e4856d34cfae}
nx                      OptOut
hypervisorlaunchtype    Auto
detecthal               Yes

Ninject, Primer – Contextual Binding

Hi,

I am currently learning how to use Ninject as a Inversion of Control and Dependency Injection tool.

I have created a very simple Console Application that is based on the tutorials at github. As I learn all the cool features of Ninject, I will then update my blog e.g. When I start learning about conventions and custom providers etc

My first Class File has custom attributes that I can use to apply contextual/conditional binding:

——————————CustomNinjectAttributes.cs————————–

using  System; 

namespace NinjectTutorial 
{ 
    public class RangeAttribute : Attribute{} 

    public class ThrowingAttribute : Attribute { } 

    public class MeleeBladeAttribute : Attribute { } 
}

—————————— END CustomNinjectAttributes.cs————————–

We will use the above vocabulary on selected properties of Player types in the game (e.g. Warrior, Ninja, Samurai)

Ok, so the next part is to define all the weapons available. Then , we will define the player types and then use Ninject to detect the players weapon based on the attributes.

Ok, so the weapons are:

—————————————–Weapons.cs——————————————–

using System;

namespace NinjectTutorial 
{ 

    public interface IWeapon 
    { 
        void Hit(string target); 
    } 

    public class Sword : IWeapon 
    { 
        public void Hit(string target) 
        { 
            System.Console.WriteLine("Chopped {0} clean in half", target); 

        } 
    } 

    public class Bow : IWeapon 
    { 
        public void Hit(string target) 
        { 
            System.Console.WriteLine("Arrow hit target in the Bulls eye!", target); 

        } 
    } 

    public class Shuriken : IWeapon 
    { 
        public void Hit(string target) 
        { 
            Console.WriteLine("Pierced {0}'s armor", target); 
        } 
    }  
}

—————————————–END Weapons.cs——————————————–

Now that we have the weapons defined, lets then use Property injection in combination with contextual binding based on decorating properties with custom attributes that we defined above!

—————————————–MarksMan.cs——————————————–

using System; 
using Ninject; 

namespace NinjectTutorial 
{ 
    public class MarksMan 
    { 
        [Inject, Range] 
        public IWeapon Weapon 
        { 
            get; 
            set; 
        } 

        public void Attack(string target) 
        { 
            Weapon.Hit(target); 
        } 
    } 
}

—————————————–END MarksMan.cs——————————————–

—————————————–Ninja.cs——————————————–

using System; 
using Ninject; 

namespace NinjectTutorial 
{ 
    public class Ninja 
    { 
        [Inject, Throwing] 
        public IWeapon Weapon 
        { 
            get; 
            set; 
        } 

        public void Attack(string target) 
        { 
            Weapon.Hit(target); 
        } 
    } 
}

—————————————–END Ninja.cs——————————————–

—————————————–Samurai.cs——————————————–

using System; 
using Ninject; 

namespace NinjectTutorial 
{ 
    public class Samurai 
    { 
        [Inject, MeleeBladeAttribute] 
        public IWeapon Weapon 
        { 
            get; 
            set; 
        } 

        public void Attack(string target) 
        { 
            Weapon.Hit(target); 
        } 
    } 
}

—————————————–END Samurai.cs——————————————–

Steps to notice

  • We use the Inject attribute in combination with the custom attribute
  • This means when we define bindings we can now have conditions based on custom attribute names which are strongly types
  • You do not need custom attributes you could use strings, but then you lose type safety.
    Excellent, now the last part of the setup is to create a custom Ninject module. Note that when you create a module, it will not be called directly, but Ninject will detect and load it for you, when you ask it to.
    ok, so lets create a module that does all the binding stuff for us, so we can keep our game code clean!

—————————————– AllFighterModule .cs——————————————–

using System;

using Ninject;

using Ninject.Modules;

namespace NinjectTutorial

{

    public class AllFighterModule : NinjectModule

    {

        public override void Load()

        {

            Bind<IWeapon>().To<Sword>().WhenTargetHas<MeleeBladeAttribute>();

            Bind<IWeapon>().To<Bow>().WhenTargetHas<RangeAttribute>();

            Bind<IWeapon>().To<Shuriken>().WhenTargetHas<ThrowingAttribute>();

            Bind<Samurai>().ToSelf();

        }

    }

}

—————————————–END  AllFighterModule .cs——————————————–

As we can see when use the WHEN keyword to detect the decorated custom attributes and then bind the appropriate concrete class.

Now to run the game, lets check out the console application

———————————————Program.cs———————————————-

using System;

using Ninject;

namespace NinjectTutorial

{

    class Program

    {

        public static void Main()

        {

            IKernel kernel = new StandardKernel();

            kernel.Load(AppDomain.CurrentDomain.GetAssemblies()); //Go Load Ninject Modules

            var samurai = kernel.Get<Samurai>();

            var marksMan = kernel.Get<MarksMan>();

            var ninja = kernel.Get<Ninja>();

            samurai.Attack("The Boss Mob!");

            marksMan.Attack("The Eagle!");

            ninja.Attack("The Robber!");

            System.Console.ReadKey();

        }

    }

}

———————————————End Program.cs———————————————-

Notice here, that we load the kernel and we also tell the kernel to find the modules! So

kernel.Load(AppDomain.CurrentDomain.GetAssemblies()); //Go Load Ninject Modules

will go and automatically load the AllFighterModule and get the bindings, this is done because the AllFigterModule extends the class : NinjectModule

The output of our cool little game is:

image

So our little warriors are working hard to keeping the peace with Ninject technology 🙂

I hope this helps you getting started with Ninject.

Welcome

Hi Folks,

I have just started out on a home project for XNA Development. The game is going to be a 2-D platformer, which will be a cross between Wonder Boy and Super Mario. It will also be utilizing the Farseer physics engine, which I hope will add an extra dimension of play to the game.

What is the game called? The title for now is The Dark Yogi. Players will need to embrace themselves for a fun filled adventure in a world of Fireballs, Magic Carpets and exotic worlds, some real, some in the world of consciousness or is it. All the levels will have their own unique set of rules that the Dark Yogi will need to traverse to conquer his self.

Helping seemingly innoccent people in the game could cause more harm than good in the world of The Dark Yogi! Stay Tuned.

Regards

Optimising SQL Server Disk subsystem – 64K

Hi Folks,

Nope this is not a job offer for 64K 🙂

Today I was having a chat with our SQL developer, as we are looking for a good DBA, once of the topics that came up was the B-Tree (Balanced Tree) structure for the SQL Storage engine. I was mentioning that the ideal DBA should at least understand how 64K extents , each containing 8 x 8k pages can cause some issues if your disk partitions are not aligned.

Anyway, we got into a heated debate of a DBA should know some of these principles. I thought to myself if I was going to win this discussion, I would need to pull something that everyone has heard of and apply my defence, and so I did!

If we use a DBCC ShowContig for a table, we will find the first two fields are the number of pages scanned and then the number of extents.

Now theoretically, for a system (Reporting system at that), the fill factor will be high, due to index references being appended to the B-Tree structure, so lets assume that we have such a reporting system that never gets a page split.

Then for a 100% fill factor index system, we should find that the (number of pages / 8 )  = number of extents.

This is of course the starting point to how SQL server detects logical fragmentation, whilst taking the fill factor into account.

Of course all DBA’s should know this, and so I applied it to disk partition alignment, and finally convinced my team mate 🙂 Since a good DBA will alter index fill factors for a reporting, OLAP, Transaction system respectively.

So, what about disk cluster alignments. Well it is important to optimise the disk for the way SQL stores day in 8K pages and 64k extents.

Microsoft discusses this in allot of detail on MSDN and any DBA wanting to optimise the Disk Subsystem, especially if you forked out allot of money for the disks such as a RAID 10 configuration.

So, what is the cluster size of a SQL optimised disk? it should of course be 64K!

Here is an example in which the F: drive is created on disk 3, aligned with an offset of 1,024 KB, and formatted with a file allocation unit (cluster) size of 64 KB.

However, aligning the partition will also be a crucial factor to disk usage. We must start the alignment and a place where we can ensure 64k extent FITS SNUGLY into a 64k cluster and not Overflow into another one.

Command Line Syntax

C:\>diskpart
Microsoft DiskPart version 6.0.6001
Copyright (C) 1999-2007 Microsoft Corporation.
On computer: DevMachine

DISKPART> select disk 3
Disk 3 is now the selected disk.
DISKPART> create partition primary align=1024
DiskPart succeeded in creating the specified partition.
DISKPART> assign letter=F
DiskPart successfully assigned the drive letter or mount point.
DISKPART> format fs=ntfs unit=64K label=”MyFastDisk” nowait


Want to know more?

The article can be read here.

http://msdn.microsoft.com/en-us/library/dd758814.aspx

I hope this will help any DBA’s out there when planning a SQL dedicated disk subsystem and put the companies money in well spent hardware into optimal use.

BizTalk: Dynamic SFTP, SOAP adapter and synchronised delivery notification within an orchestration using the Custom SQL send adapter

Hi Folks,

I recently had to build a dispatching system, where a message would be received from our web service. The message would then be saved to the database with:

Stage: IMPORT and Status: SUCCESS

A standard BizTalk SQL Receive location would pull the messages and change the message in the SQL table to:

Stage: BizTalk and Status: Processing

Envelopes and De-batching

The above pull is done in batch mode, this means, that SQL will pull a batch of records and use the FOR XML clause. However when the message is built in SQL, there is NO root node. However the SQL adapter can inject one, see image below on how it does it:

image

Now the messages are DEBATCHED by using an ENEVELOPE schema which will recognise the xml data, how is this enforced? The Receive pipeline on the SQL adapter is set to: XMLReceive.

There is allot of information out there regarding DEBATCHING and using envelopes. However, when you create a XSD to represent the xml data, just remember to ensure the property for an ENVELOPE is set:

image

This property is found on the Schema Design in Visual Studio.

So, now the messages are de-batched into the BizTalk message box.

An orchestration will have a DIRECT receive port with a filter that subscribes to this type of debatched record. So if the schema for the batch was BATCHRecords.xsd containing a collection of Records.xsd schema, then the orchestration will subscribe to the schema type of Records.xsd. I always define the individual record schema first and then define the batchrecord schema, then in the batch schema I just IMPORT the individual record schema.

image

Ok, we getting diverted, but understanding envelopes is crucial in BizTalk when pulling data from SQL.

Orchestration

Now that the message is in the orchestration we need to have the following goals in mind:

  • If the message succeeds, a part of the message needs to be extracted using Xpath and saved to the SQL database, by calling a stored procedure with parameters that accept a Xml document and other variables. The stage and status is then set to END, SUCCESS
  • The default SQL adapter cannot do this very well, so I have a custom SQL adapter to do it, you can read up about it here:

    Romiko-Custom SQL Adapter

  • If the message fails, then the original message is sent to SQL and Stage and Status is set to END, FAILED.
  • If message fails being dispatched to an external SOAP or SFTP destination then the orchestration must handle the delivery failure and MUST NOT suspend the SFTP or SOAP send port, since the message is flagged in SQL as failed, so it can always be reset from the database using an interface for help desk.
  • A way to store the ACKNOWLEGEMENT from the SOAP or SFTP so we can define if the delivery failed. The orchestration MUST NOT use an asynchronous way to send to SFTP or SOAP and then carry on executing shapes further down the line.
  • The custom SQL adapter can be asynchronous, since this is in house part, if it fails, we want to be able to resume the port, so the SQL aspect MUST be resumable, else help desk gets no answer and see messages with stage BIZTALK and status PROCESSING.

 

Now, lets dispel some of the gossip out there about delivery notification.

Delivery notification will always give you a NACK or ACK back when a message fails or success respectively when sending to a port. This is done if the port is enable for delivery notification.

Now let me get rid of some incorrect information out there:

  1. You DO NOT need a Long Running/ATOMIC Transaction scope to use Delivery Notification
  2. You CAN use delivery notification on Dynamic Ports 🙂

I say this, since I see books, a blogs saying that your delivery notification send shape must be in a scope that is set to Long Running or Atomic, not true at all…

So what do you need.

  1. A scope (Transaction = NONE), with the last shape being the send to the SOAP or SFTP port
  2. The SOAP and SFTP port must be setup for delivery notification
  3. The scope must be set to Synchronised
  4. A Delivery Notification Exception handler, A Soap handler (for soap failures) and a SYSTEM.Exception scope (NOT general exception, have no clue why it is default in BizTalk orchestration designer, it is not cool, always use a System.Exception type, then you have access to the Exception ex variable to get the message e.g. Trace.WriteLine(ex.Message)
  5. The ports enabled for delivery notification can be dynamic, however in a message construct, you must set the retry to 0, no point using retries, if you are flagging an external system with a FAIL.

ANY shapes after the send shape IN THE SCOPE will execute asynchronously, so ensure those shapes do not depend on the delivery, perhaps a DEBUG TRACE or something that you like to have for debugging. Another nice thing to have is a global boolean variable that is used to detect if a NACK was sent so you can always check this bool value AFTER the scope where the send shape was in, to ensure a ACK was received to continue processing, else you know it was a NACK and can then safely call the SQL code to send the message to SQL with Failure.

After the exception, is where the above logic for the SQL persistence can be put, also in its own scope, that is not set to synchronise and with no delivery notification, so we can also resume the send port of sql, but never resume SFTP or SOAP.

Below are screen images of the orchestration I used for this.

image

image

We subscribe using promotes properties of STAGE and STATUS.

Above we get the message and then detect if it is for SOAP sending or SFTP using some Distinguished fields.

Here is the if expression:

Record.MetaData.Protocol.Type == "SOAP"

Ok, so now lets check out the SFTP and then we will do the SOAP.

First thing to notice is that BizTalk does not support SFTP, however some cool developers have made one, and you can download it here:

Blogical.Shared.Adapters.SFTP:

http://sftpadapter.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=19784

Ok, so here is the control flow:

image

 

image

Another thing is that SFTP is Request Model, not Request/Response like SOAP. you will see in the soap branch later that I will extract the response from the soap response message and use that, where as with SFTP, I use the originally request for database storage.

In the message construct we ensure we set the port retry to 0:

Here is the code for the message construct to set SFTP properties dynamically, I used distinguished fields to access the meta data from the message, basically when SQL got the the message it did a join with a control table to find out the destination SFTP location depending on the data pulled 🙂

//Romiko van de dronker 14/01/2010
// Set Port Properties
Port_Dynamic_OneWay(Microsoft.XLANGs.BaseTypes.Address) = "SFTP://" + Record.MetaData.Protocol.FTPProperties.SSHHost + ":" + Record.MetaData.Protocol.FTPProperties.SSHPort + "/";
// Assign the ProcessSaleslead data to the new output message
ProcessSalesLeadMessage = xpath(Record," /*[local-name()=’Record’ and namespace-uri()=’
http://Romiko.Dispatch.Schemas’]/*[local-name()=’Data’ and namespace-uri()=’http://Romiko.Dispatch.Schemas’]/*[local-name()=’ProcessSalesLead’ and namespace-uri()=’http://www.starstandard.org/STAR/5′]");
ProcessSalesLeadMessage(BTS.RetryCount) = 0; // To support NACK from port.
// Set SFTP properties
ProcessSalesLeadMessage(BTS.OutboundTransportType) = "SFTP";
ProcessSalesLeadMessage(Blogical.Shared.Adapters.Sftp.Schemas.host) = Record.MetaData.Protocol.FTPProperties.SSHHost;
ProcessSalesLeadMessage(Blogical.Shared.Adapters.Sftp.Schemas.portno) = System.Int16.Parse(Record.MetaData.Protocol.FTPProperties.SSHPort);
ProcessSalesLeadMessage(Blogical.Shared.Adapters.Sftp.Schemas.user) = Record.MetaData.Protocol.FTPProperties.SSHUser;
ProcessSalesLeadMessage(Blogical.Shared.Adapters.Sftp.Schemas.password) = Record.MetaData.Protocol.FTPProperties.SSHPassword;
ProcessSalesLeadMessage(Blogical.Shared.Adapters.Sftp.Schemas.remotepath) = Record.MetaData.Protocol.FTPProperties.SSHRemotePath;
ProcessSalesLeadMessage(Blogical.Shared.Adapters.Sftp.Schemas.remotefile ) = .Helper.OrchestrationHelper.BuildDateTime(System.DateTime.Now) + "." + Record.MetaData.Protocol.FTPProperties.SSHRemoteFile;
//Connection TimeOut
ProcessSalesLeadMessage(Blogical.Shared.Adapters.Sftp.Schemas.connectionlimit)= System.Int16.Parse(Record.MetaData.Protocol.FTPProperties.SSHConnectionLimit);
//Optional Settings – Not yet supported, as null values can exist, need to build a helper class to not assign nulls, if they null.
//Debug
ProcessSalesLeadMessage(Blogical.Shared.Adapters.Sftp.Schemas.trace) = System.Boolean.Parse(Record.MetaData.Protocol.FTPProperties.SSHDebugTrace);

Ok, now that the message is constructed, all we do is create a scope that is SYNCRHONISED and ensure the SFTP port delivery notification is on:

image

image

So above we set Delivery Notification to Transmitted.

Now anything to do with SFTP goes into this scope and NOTHING else.

Notice my exception types, I have a delivery and system.exception:

image

image

In the exception, you can set the state to Failed 🙂

SendSuccess = false;
Stage = "END";
Status = "FAI";
Error = "SFTP Failure, " + e.Message;
System.Diagnostics.Trace.WriteLine("BIZTALK: Throwing a Delivery Notification Error" + e.Message);

After this we then have a condition statement to see if the delivery was a success, if it was it executes the branch of SQL to make it a success else executes the sql to fail the record.

Notice this is a NEW SCOPE: (UPDATE SQL) tranaction = none

why? Well, delivery notification will only work in it’s scope, so a new scope is needed for anything new that MUST continue, it can be in a nested scope like ours or in the orchestration default scope, I like it is a nested scope for neatness and control.

if expression is:

SendSuccess == true

If this is the case, I will create a new message type and send the data to SQL, This is done in the last message construct:

//Romiko van de dronker 14/01/2010
OutRecord = Record;
OutRecord(MMIT.Dispatch.Schemas.Stage) = Stage;
OutRecord(MMIT.Dispatch.Schemas.Status) = Status;

 

Also with the CUSTOM SQL adapter, I send this data to the store procedure, note I send XML directly to SQL 🙂

image 

For the SOAP aspect, the same logic applies. However there are some catches.

The URL address set in the orchestration is in this format SOAP://myaddress.com/mypage.asmx.

Now when using a static adapter, this is not a problem, since in the adapter you set the URL to http:// format.

There is no shortcut, you need to make a custom pipeline component to handle this. The adapter will understand the SOAP format, however the pipeline will then do the magic and replace the SOAP with HTTP.

Another thing, you can even set the ASSEMBLY and proxy class for the SOAP adapter dynamically, the message that came into the orchestration has this information, and I set this at runtime 🙂 Another cool feature is I have a SOAP Header and a SOAP body, so my soap proxy has two method parameter, this means that my multipart message MUST match the paramter types of the soap proxy. lets see how this works:

The MULTIPART message looks like this:

For my SOAP proxy method paramters, I use type XmlDocument for both, so my multipart message that I will send to the SOAP adapter is this:

image

The header uses a schema from:

<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;

<UsernameToken>

<Username>string</Username>

<Password>string</Password>

</UsernameToken>

<KeyIdentifier>string</KeyIdentifier>

</Security>

It is a common schema from oasis.

So what we going to do is parse the message body and the header to the SOAP adapter and the proxy will do the rest:

Here is my proxy class code:

using System;
using System.Net;
using System.Web.Services.Protocols;
using System.Xml;
using Romiko.Proxies.MMITGMDSConsumer;
using System.Xml.Serialization;

namespace Romiko.Proxies.Suppliers
{
    [System.Web.Services.WebServiceBindingAttribute(Name = "StarBodToMMITSoap", Namespace = "
http://Romiko.WebServices/")]
    public partial class MMITConsumer : System.Web.Services.Protocols.SoapHttpClientProtocol
    {

        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://Romiko.WebServices/SubmitStarProcessSalesLead", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
        public AcknowledgeSalesLeadType Dispatch(XmlDocument MessagePartBody, XmlDocument MessagePartSOAPHeader)
        {
            try
            {
                System.Diagnostics.Trace.WriteLine("ServiceProxy:Dispatch to " + this.Url);
                System.Diagnostics.Trace.WriteLine("ServiceProxy:Message in is: " + MessagePartBody.OuterXml);
                System.Diagnostics.Trace.WriteLine("ServiceProxy:Header is: " + MessagePartSOAPHeader.OuterXml);

                StarBodToMMIT ws = new StarBodToMMIT();
                XmlSerializer X = new XmlSerializer(typeof(ProcessSalesLeadType), "
http://www.starstandard.org/STAR/5");
                ProcessSalesLeadType processSalesLead = (ProcessSalesLeadType)X.Deserialize(new XmlNodeReader(MessagePartBody));

                ws.Url = this.Url;

                XmlSerializer Y= new XmlSerializer(typeof(SecuritySoapHeader), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
                ws.Security = (SecuritySoapHeader)Y.Deserialize(new XmlNodeReader(MessagePartSOAPHeader));

                AcknowledgeSalesLeadType response = ws.SubmitStarProcessSalesLead(processSalesLead);           
                return response;

            }
            catch (WebException)
            {
                // To use the retry functionality of the send port
                // This exception type includes time outs and service unavailable from the web service.
                throw;
            }
            catch (Exception e)
            {
                throw new Exception("Problems occured in the proxy:" + e + e.InnerException);
            }
        }
    }
}

BizTalk will automatically detect the message parts, and the name they called is resolved to the proxy parameter names, as you can see they the same as the multi-part message 🙂

 

Ok, so that part was easy. How do you tell the soap adapter to do this dynamically, the magic is in the message construct:

//Romiko van de dronker 15/01/2010

// Assign the ProcessSaleslead data to the new output message
ProcessSalesLeadMessageRequest.MessagePartBody = xpath(DRONKYRecord," /*[local-name()=’DRONKYRecord’ and namespace-uri()=’
http://Romiko.DRONKY.Dispatch.Schemas’]/*[local-name()=’Data’ and namespace-uri()=’http://Romiko.DRONKY.Dispatch.Schemas’]/*[local-name()=’ProcessSalesLead’ and namespace-uri()=’http://www.starstandard.org/STAR/5′]");

//Assign SOAP Header to Context
ProcessSalesLeadMessageRequest.MessagePartSOAPHeader = Romiko.DRONKY.Helper.OrchestrationHelper.BuildSoapHeader(DRONKYRecord.MetaData.Protocol.SOAPProperties.SOAPHeaderUserName, DRONKYRecord.MetaData.Protocol.SOAPProperties.SOAPHeaderPassword);

// Retry Count MUST be 0 for NACK management, also we in a synchronisation scope.
ProcessSalesLeadMessageRequest(BTS.RetryCount) = 0; // To support NACK from port.

// Set Port Properties
Port_Dynamic_SOAP(Microsoft.XLANGs.BaseTypes.Address) = DRONKYRecord.MetaData.Protocol.SOAPProperties.SOAPURI;
System.Diagnostics.Trace.WriteLine("URI is: " + DRONKYRecord.MetaData.Protocol.SOAPProperties.SOAPURI);

// Set SOAP Proxy assembly
ProcessSalesLeadMessageRequest(SOAP.AssemblyName) = DRONKYRecord.MetaData.Protocol.SOAPProperties.SOAPAssemblyName;
ProcessSalesLeadMessageRequest(SOAP.TypeName) = DRONKYRecord.MetaData.Protocol.SOAPProperties.SOAPTypeName;
ProcessSalesLeadMessageRequest(SOAP.MethodName) = DRONKYRecord.MetaData.Protocol.SOAPProperties.SOAPMethodName;

//Set Misc SOAP settings
ProcessSalesLeadMessageRequest(SOAP.ClientConnectionTimeout) = System.Int32.Parse(DRONKYRecord.MetaData.Protocol.SOAPProperties.SOAPClientConnectionTimeOut);
ProcessSalesLeadMessageRequest(SOAP.UseSoap12) = System.Boolean.Parse(DRONKYRecord.MetaData.Protocol.SOAPProperties.SOAPUseSoap12);

You can see above, I dynamically set the assembly, class and method to call:

Cool!

ok, the magic part I spoke of for the pipeline, i assume you can build them,so here is the code of the execute and the custom method:

First set the logical port properties for the SEND Pipeline (ENCODER)

image

Ok, here is the partial code of the pipeline:

note the part that replaces SOAP string with HTTP, i do some extra checks, to support HTTPS on default ports 80 and 443 🙂

public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
        {
            try
            {
                System.Diagnostics.Trace.WriteLine("Pipeline:Execute entry");

                string address = (string)inmsg.Context.Read("OutboundTransportLocation", "http://schemas.microsoft.com/BizTalk/2003/system-properties");
                string method = (string)inmsg.Context.Read("MethodName", "http://schemas.microsoft.com/BizTalk/2003/soap-properties");

                System.Diagnostics.Trace.WriteLine("Pipeline:Updating context");

                Uri uri = new Uri(address);

                string protocol = "https";

                if (uri.Port == 80 || uri.Port == 8080)
                    protocol = "http";

                //Send over HTTP or HTTPS
                string addr = protocol + "://" + uri.Host + ":" + uri.Port + uri.PathAndQuery;
                System.Diagnostics.Trace.WriteLine("HTTP url is: " + addr);
                //Here is the magic where we can now convert SOAP://…. to
HTTP://…. and now we ready for some full contact generic web service proxy calls!

                inmsg.Context.Write("OutboundTransportLocation", "http://schemas.microsoft.com/BizTalk/2003/system-properties", addr);
                inmsg.Context.Write("Operation", "
http://schemas.microsoft.com/BizTalk/2003/system-properties", method);

                System.Diagnostics.Trace.WriteLine("Pipeline:End, Number of messages parts: " + inmsg.PartCount);
                System.Diagnostics.Trace.WriteLine("Pipeline:End, Body Part name:" + inmsg.BodyPartName);
                return inmsg;
            }
            finally
            {
                System.Diagnostics.Trace.WriteLine("Pipeline:Execute exit");
            }
        }

 

Well I hope this has shown how powerful orchestration development can be, and in fact you can CONTROL how an orchestration resumes by using scopes to control persistence points, in my case, I want the orchestration to NEVER suspend and always succeed, and handle failures by updating status states in the SQL database for support to handle 🙂

As soon as I get time, I will work on WCF and other cool features of BizTalk itching to upgrade to BizTalk 2009! Which I am doing right now 🙂

Good Luck.

Web Services Security

Hi Folks,

When it comes to SOAP security, I use the following schema for the SOAP Header:

http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd

 

It is really easy to use. Just have this class in your webservices project:

——–SecuritySoapHeader.cs

using System.Xml.Serialization;
using System.Web.Services.Protocols;

namespace Romiko.Hello.WebServices
{

    [XmlType(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")]
    [XmlRoot("Security", Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", IsNullable = false)]
    public class SecuritySoapHeader : SoapHeader
    {
        public UsernameTokenType UsernameToken;
        public class UsernameTokenType
        {
            public string Username;
            public string Password;
            public string KeyIdentifier;
        }

    }
}

——————————-

Then just add a public property on the webservice.asmx.cs code behind like:

public class Hellow World: System.Web.Services.WebService
    {
        private SecuritySoapHeader security;
        public SecuritySoapHeader Security
        {
            get { return security; }
            set { security = value; }
        }

        [WebMethod(Description = "Hello System.", EnableSession = false, TransactionOption = TransactionOption.Disabled, BufferResponse = false, MessageName = "", CacheDuration = 0)]
        [SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]
        [SoapHeader("Security", Direction = SoapHeaderDirection.In)]
        public Data_Records PullRecords(int BatchSize)
        {
            ValidateInputCredentials();
            return GetDataRecord(BatchSize);
        }

Notice I do not use everything from the OASIS xsd, just a username, password and GUID key 🙂

 

This will then be automatically generated in the WSDL in the types section:)

<s:schema elementFormDefault="qualified" targetNamespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
  <s:element name="Security" type="s2:SecuritySoapHeader" />

<s:complexType name="SecuritySoapHeader">
<s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="UsernameToken" type="s2:UsernameTokenType" />

  </s:sequence>

  <s:anyAttribute />

  </s:complexType>

<s:complexType name="UsernameTokenType">
<s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="Username" type="s:string" />

  <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />

  <s:element minOccurs="0" maxOccurs="1" name="KeyIdentifier" type="s:string" />

  </s:sequence>

  </s:complexType>

  </s:schema>

  </wsdl:types>

What is really nice as well is introducing an Enterprise Service Bus Management system, which can centrally audit all web services and authenticate users, then just publish the ESB management pages in SharePoint!

I will see, if I get time, I will show you how to build cool ESB Management systems 🙂

I just finished university in my spare time, so this will certainly free up some time for blogs!

XML SelectSingleNode or SelectNodes and dealing with namespaces the easy way

Hi Folks,

Sometimes namespaces can be a real pain. Especially when child elements in an XML document have multiple namespaces etc.

Imagine a document like this:

<Root xmlns="http://www.example.com">

<Child xmlns="http://www.romiko.com/>
<Child xmlns="http://www.romiko.com/>

</Root>

 

To select the data  for all childs you have two ways to do it:

ns.AddNamespace("ro", "http://www.example.com");
ns.AddNamespace("ch", "http://www.romiko.com");
XmlNodeList nodes = doc.SelectNodes("/ro:Root/ch:Child", ns);

OR

XmlNodeList nodes = doc.SelectNodes("/*[local-name()=’Root’]/*[local-name()=’Child]");

As You can see I prefer the latter, less code and is XPATH compliant.