A random collection of epiphanies, thoughts and problem solutions pertaining to .NET and BizTalk.

Wednesday, October 27, 2004

Got tired of running Deployment Wizard?


I found it is very annoying to run the BizTalk deployment wizard to deploy or undeploy the assemblies during development phase. Especially when you have multiple assemblies to deal with. You can actually write a simple batch file to automate the deploy/undeploy process. BizTalk provides a BTSDeploy.exe in the installation directory that can take various arguments to perform these tasks easily. The following code (undeploy.bat) is a very rough sample for the undeployment. The deployment step is just the opposite. In case you don't know how to find out the public key token of your assembly, you could use these commands: sn -T assembly.dll and sn -t keyfile.snk.


@echo off
SETLOCAL

::
:: Set the deploy environmental variables for App
::
SET server=dbserver
SET db=BizTalkMgmtDb
SET btsdir="C:\Program Files\Microsoft BizTalk Server 2004"
SET outdir=..\App\bin\Development
SET log=.\undeployapp.log

::
:: The following section could be repeated if mutiple assemblies
:: to be undeployed...
::
SET name=App
SET version=2.0.0.0
SET pkt=29068414d03ece02
SET culture=neutral

echo Undeploy %name% %version% from GAC and %db% on %server% ...
::
:: Perform undeployment; use BTSDeploy.exe
::
%btsdir%\BTSDeploy
REMOVE SERVER=%server% DATABASE=%db%
NAME=%name% VERSION=%version% CULTURE=%culture%
PUBLICKEYTOKEN=%pkt% UNINSTALL=True LOG=%log%

pause

The node to be inserted is from a different document context


Inside your message assignment shape, if you try to do :


Construct MsgB
{
theXmlDoc.DocumentElement.AppendChild
(
xpath
(
MsgA,
"//*[local-name()='someElement']"
)
);
MsgB = theXmlDoc;
}

You will run into this error:

Event Type: Error
Event Source: XLANG/s
Event Category: None
Event ID: 10034
Date: 10/27/2004
Time: 4:13:29 PM
User: N/A
Computer: B00D059B675E2
Description:
Uncaught exception terminated service A, instance B

The node to be inserted is from a different document context.

Exception type: ArgumentException
Source: System.Xml
Target Site: System.Xml.XmlNode AppendChild(System.Xml.XmlNode)
Help Link:
Additional error information:

SOLUTION: This is because the node to be copied belongs to another Xml document and is not recognized by the destination xml document. In order to make it work, you will need to import it first. If you read MSDN's documentation for the XmlNode.AppendChild() method, you will notice the following description:

...
If the node being inserted was created from another document, you can use XmlDocument.ImportNode to import the node to the current document. The imported node can then be inserted into the current document. ...

Therefore, all you need to do is to add XmlDocument.ImportNode() method in the message assignment expression editor:



Construct MsgB
{
theXmlDoc.DocumentElement.AppendChild
(
theXmlDoc.ImportNode
(
xpath
(
MsgA,
"//*[local-name()='someElement']"
)
)
);
MsgB = theXmlDoc;
}


Cannot retrieve list of objects due to a WMI provider failure. New transaction cannot enlist in the specified transaction coordinator.


Cannot retrieve list of objects due to a WMI provider failure. New transaction cannot enlist in the specified transaction coordinator.


This problem occurs when you run the BizTalk Server across the fire wall. Take a look at the following links:


KB 250367


KB 306843


KB 300083


Ports need to be opened

Sunday, October 24, 2004

Windows Command Line Tricks


  • Command Line Expansion:

    I am sure you like the command line expansion capability of csh, tcsh and bash in unix family of operating systems. You can have the same capability in Windows Command Line if you enable it. :-) You can use "tab" to expand the whole command line argument after you give a few starting characters. To enable this capability, set the following registry key value to 9.

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\PathCompletionChar


  • Open File Explorer From cmd and Set Address to Current Working Directory:

    Developers constantly spend time in command line and sometime it is useful to start up the file explorer from the comand line environment. It will be very cool and save us a little bit time if the file explorer opened will point to the same working directory. You can do this easily with this command:
    C:\Program Files\Microsoft BizTalk Server 2004> explorer %cd%
    This command will open up a file explorer and take you to directory:
    C:\Program Files\Microsoft BizTalk Server 2004

Thursday, October 21, 2004

The property 'TargetSite' on type 'System.Exception' cannot be serialized because it is decorated with declarative security permission attributes.

Detailed error:
The property 'TargetSite' on type 'System.Exception' cannot be serialized because it is decorated with declarative security permission attributes. Consider using imperative asserts or demands in the property accessors.



Solution: System.Exception object can not be serialized to transfer over the HTTP channel. Obviously, we need to provide some mechanism to serialize its state to some transferable medium like string. And on the other end, typically web service, we need to deserialize it back to the exception object.



I have a BaseException class that derives from System.Exception class. It has
a public property called "ExceptionState" that serializes it to Base64String representation. It also has a static method "Reconstruct" that reconstructs it from the Base64String back to the BaseException object.




public class BaseException : Exception, ISerializable
{

//...

string state;
static BinaryFormatter binaryFormatter = new BinaryFormatter();

/// <summary>
/// Persiste BaseException object to the base 64 string. This property returns
/// a string representation of the exception state which could be used to
/// reconstruct this exception if desired. <see cref="Reconstruct"/> method.
/// This property is introduced to fix the following issue:
/// The property 'TargetSite' on type 'System.Exception' cannot be serialized
/// because it is decorated with declarative security permission attributes.
/// Consider using imperative asserts or demands in the property accessors.
/// </summary>
public string ExceptionState
{
get
{
if (state == null)
{
MemoryStream stream = new MemoryStream();
binaryFormatter.Serialize(stream, this);
stream.Seek(0, SeekOrigin.Begin);
state = Convert.ToBase64String(stream.ToArray());
}
return this.state;
}
}

/// <summary>
/// Reconstructs a <c>BaseException</c> from the supplied exceptionState
/// string. <see cref="ExceptionProperty"/> property comments.
/// </summary>
/// <param name="exceptionState">
/// Base 64 string representation of the xception</param>
/// <returns>
/// A reconstructed <c>BaseException</c> object; null if reconstruction failed.
/// </returns>
public static BaseException Reconstruct(string exceptionState)
{
byte [] buffer = Convert.FromBase64String(exceptionState);
Stream stream = new MemoryStream(buffer, 0, buffer.Length, false);
stream.Seek(0, SeekOrigin.Begin);
object obj = binaryFormatter.Deserialize(stream);
return obj as BaseException;
}
}

Scritping Functoid Catch


I experienced a problem when I was using the Inline XSLT inside the scripting functoid. I entered the XSLT first, then I scrolled the "Script type" dropdown to check out the template of "Inline C#". Then I clicked on the "OK" button without noticing that "Configure Functoid Scripts" dialog actually overwrites the the script type of my choice "Inline XSLT" with "Inline C#", even though your intention is to use XSLT. As a matter of fact, when you scroll the "Script type" dropdown to any other script types in front of the "Inline XSLT" inside the "Script type" dropdown, BizTalk will automatically uses the first available in the list even somtime it only has script in comments. When you compile your project, it will not signal error since all of the commented code, i.e. empty script, is considered valid by compiler. But when you run your orchestration, it will bomb. The solution is you need to rearrange the precedence of the inline scripts. To do this, right click inside of the map area; then go to the property window and bring up the "Script Type Precedence" dialog.
Image Hosted by ImageShack.us
I would test any BizTalk mapper before I compile my projects. To do so, simply right click on your map file and select "Test map" from the context menu.

Monday, October 18, 2004

BizTalk Xml Links ...


  • Import, Include or Redefine


    Even though you could use <xs:import> or <xs:include> to reuse existing schemas, I found that BizTalk having some proprietary processing for <xs:include>. It will copy the included schema verbatim whenever you place your <xs:include> node. Moreover, the schemas will also be included whenever they are referenced. Thus, you will have multi-rooted master schema if you use <xs:include>. I prefer to use the <xs:import> because it will maintain the single root in the master schema even you reference multiple existing external schemas.




  • Assign messages


  • Xml Namespace and XPATH


  • Elements vs. Attributes


  • IBM's When to use elements versus attributes

Sunday, October 17, 2004

Yet another BizTalk Naming Guideline Recommendations

For all BizTalk orchestration shapes, I would recommend to call a shape with its name (or its shorthand) and suffix it with a succint description. This is only a recommendation. You don't have to follow this convention. The recommendation strives to promote a common set of guidelines.



...................................................................
Shape Short Example
...................................................................
Call Orchestration CallOdx CallOdx_AssembleReply
Call Rules CallRule CallRule_LoanDecisioning
Compensate Compensate Compensate_BadTransactions
Construct Message Mkmsg Mkmsg_GetEntityParams
Decide Decide Decide_ProcessBorrower
Delay Delay Delay_OneHour
Group Grp Grp_GetFirstEntity
Listen Listen Listen_IncomingReq
Loop Loop Loop_ProcessAllApplications
Message Assignment Assign Assign_EntityMatchResultToReplyMsg
Parallel Actions Para Para_GetMatchAndMkReply
Port* Port Port_GetEntities
Receive Recv Recv_AppReq
Send Send Send_AppRep
Start Orchestration Init Init_PlaceOrder
Suspend Susp Susp_CreditEvaluationOdx
Terminate Stop Stop_CreditEvaluationOdx
Throw Exception Throw Throw_UnknownReqException
Transform Xform Xform_GetEntityParams

* Since orchestration's port name has nothing to do with the transfer protocol, the name should not contain the word like Soap, Http, File, etc.

Friday, October 15, 2004

This Assembler cannot retrieve document specification by using this type: "http://tempuri#request"


Event Type: Error
Event Source: BizTalk Server 2004
Event Category: BizTalk Server 2004
Event ID: 5720
Date: 14/10/2004
Time: 18:19:46
User: N/A
Computer: yourhost
Description:
There was a failure executing the send pipeline:
"Microsoft.BizTalk.DefaultPipelines.XMLTransmit"
Source: "XML assembler"
Send Port: "SQL://server/db/" Reason: This Assembler cannot retrieve
document specification by using this type: "http://tempuri#request".


SOLUTIONS: This is noramlly caused by the failure of BizTalk's message engine to derive the unique type from the deployed Xml Schema. Type generated by the schema will have the format of "namespace#typename". For example, if you have defined your xmlns=http://myproject and you have an root element called item. The fully qualified element type derived by the BizTalk will be: http://myproject#item. So your responsibility is to make sure:


  • Indeed you have this schema and desired root element defined

  • You don't have two or more elements with the exact same name and same namespace deployed. This includes all schemas previously deployed to the BizTalkMgmtDb. You could find the Xml namespaces are saved in the bt_XmlShare and bt_XmlShareReference tables in the BizTalkMgmtDb


Tuesday, October 12, 2004

BizTalk: 'ActiveView.ColumnAxis' is null or not an object


HAT failed to run properly, it complains about the snap in. You need download Office 2000 Web Components:
download from here

A Microsoft Distributed Transaction Coordinator problem prevented connection to the Configuration database. Exception from HRESULT: 0x8004D00E


Follow these steps:



  1. Make sure host and server can ping each other

  2. Make sure DTC service is up and running

  3. Check out kbid 839187
    SET HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSDTC\TurnOffRpcSecurity = 1

  4. If your DEV BizTalk server is on a Windows XP box with SP2 installed, take a look at this article by Florin Lazar: XP SP2 and Transactions

BizTalk: Type "http://www.w3.org/2001/XMLSchema:char" is not declared or not a simple type

If you use the datatype char(1) in the stored procedure, it will bomb when you try to generate XML schema in the "add SQL adapter wizard".


It turns out to be a BizTalk bug. You can still use char(1) and it will just work fine after applying the following fix. By default, the schema returned by SQL XML is XDR (XML data Reduced). You can observe this from the Query Analyzer. This reduced schema is not used by BizTalk; BizTalk uses the xsd. BizTalk relies on the XDRToXSD.xslt to transfrom the xdr generated by SQL Server to the desired xsd format. There's a problem in the XDRToXSD.xslt (this file locates in "C:\Program Files\Microsoft BizTalk Server 2004\"). To fix this problem change the following line:



<xsl:template match="@dt:type[.='char']" mode="convert-datatype">xs:char</xsl:template>
to:
<xsl:template match="@dt:type[.='char']" mode="convert-datatype">xs:string</xsl:template>


Thus, char(1) or char will be mapped to a xs:string. Actually, the default http://www.w3.org/2001/XMLSchema namespace has no xs:char build-in type. If you look at the following picture of the build in XMLSchema type hierachy you will find there's no xs:char.





For details about the XMLSchema build in data type click here.

Followers