BizTalk

How to Send File to MSMQ Using C#

by Ali Raza Zaidi on December 25, 2011

During the testing of BizTalk application, which read data from MSMQ. I have to write small C# routine, this routine send data to MSMQ.  If you have no knowledge about MSMQ, Please read My Post on this here.
http://www.biztalkhq.com/what-is-msmq-and-how-to-configure-it-on-windows-7/

 

To Send File on MSMQ you have to include the dll System.Messaging in your C# or Vb.net application. To Simplest code is as follow.

 

public void FileToMSMQ(string FilePath, string MsmqName)

{

//FilePath =@”e:\test.xml”;

//MsmqName= @".private$testQue";

System.Messaging.MessageQueue _TheQueue = new System.Messaging.MessageQueue(MsmqName);

System.IO.FileStream _FileStream = new System.IO.FileStream(FilePath, System.IO.FileMode.Open);

Message _Message = new Message();

_Message.BodyStream = _FileStream;

_Message.Label = System.IO.Path.GetFileName(FilePath);

_Message.Priority = MessagePriority.Normal;

_TheQueue.Send(_Message);

}
You can down sample code from here

 

 

 

 

What is MSMQ and How to configure it on windows 7

by Ali Raza Zaidi on December 25, 2011

Microsoft Message Queue (MSMQ):
MSMQ is a messaging protocol that allows applications running on separate servers/processes to communicate in a failsafe manner. A queue is a temporary storage location from which messages can be sent and received reliably, as and when conditions permit. Queues are used to receive and send the Messages.
To Install MSMQ, Go to Control Panel -> Add Remove Program -> Add Windows Component and select “Message Queuing”

 

Install MSMQ – Microsoft Messaging Queue

[click to continue…]

Today during testing and redeploying the BizTalk 2006 application, I got this error.

Change requests failed for some resources. BizTalkAssemblyResourceManager failed to complete end type change request. Unable to install the assembly into the Global Assembly Cache.

Exception: A file load exception occurred while attempting to install the assembly into the Global Assembly Cache. This error may occur if the assembly is delay signed, or if assembly was renamed after creating/signing

Only solution to this problem was to close the visual studio solution and then reopen solution, this solved temporally.  Issue appears again after second or third deployment.

After doing google, I followed these steps to remove this error.

• I have to clear the temp files at machine. For this purpose I typed %temp% at run and it opened the temporary folder. Clear all directory alternatively we can get temp directory similar to following address “ X:Documents and SettingsUserNameLocal SettingsTempBT.

• Full stop the application at BizTalk console. And stop the BizTalk host instance on application is running. Then uninstall the previous/ current versions of dll from GAC and redeploy the application. If you got error message on uninstalling the assembly error “Cannot Uninstall as it is being used by another process”, then stop the host instance, close all applications and try again. If you still cant delete the dll, restart the PC.

• Check if the project is using any reference path that does not exist. ( For this, go to project properties -> Select Reference Paths -> Delete any References that doesn’t Exist)

 

Three Schema Design Approaches

by Ali Raza Zaidi on October 13, 2011

Article reference from :   http://technologyandleadership.com/three-schema-design-approaches/

 

In a project where multiple schemas are created it is critical to decide which namespace design approach is suitable for the project: (1)should we give each schema a different targetNamespace, (2)should we give all the schemas the same targetNamespace or (3)should some of the schemas have no targetNamespace. To make this critical design decision, let me illustrate the three schema design approaches in this article.

Heterogeneous Namespace Design

1. Give each schema a different targetNamespace
2. If required to re-use another schema in the current schema we need to import it

Benefits
1. Maximise the re-use of the types with separate namespaces
2. Namespace mapped to domain specific service
3. It would be easier to model all the domain-specific types in separate files with individual namespaces
4. Easier to understand
Drawbacks
1. There will be a large number of namespaces to manage
2. There will be a large number of namespaces to import
3. The granularity of the types in import would depend on the types defined and exposed in a particular domain-specific XSD

Homogenous Namespace Design

1. Give all schemas the same targetNamespace
2. As the schemas have the same targetNamespace, the method of accessing components is “include”.

Benefits
1. No need to either import a service or schemas
Drawbacks
1. Need to handle Name collisions
2. Generate code in a single Java package, for a service
3. chances for redundant types
4. does not allow for domain-specific namespaces

Chameleon Namespace Design

Give the main schema a targetNamespace and give no targetNamespace to the supporting schemas. The no-namespace schemas will take-on the targetNamepspace of the main schema.

Benefits
1. In this scheme, schemas are able to blend in with the main schemas that use them
2. Ability to provide application-specific namespace to the schema
Drawbacks
If the schema <include>s multiple no-namespace schemas then there will be a chance of name collisions. In fact, the schema may end up not being able to use some of the no-namespace schemas because their use results in name collisions with other Chameleon components

The most widely used schema design approach is heterogeneous schema design approach. Let me illustrate this with an example.

Step1: Create a schema file named Books.xsd

 

<!-- to store book information with targetNamespace declared as tns:Books-->
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="tns:Books"
            elementFormDefault="unqualified">
    <xsd:complexType name="Book">
        <xsd:sequence>
           <xsd:element name="Author" type="xsd:string"/>
           <xsd:element name="Title" type="xsd:string"/>
           <xsd:element name="Price" type="xsd:double"/>
           <xsd:element name="Quantity" type="xsd:integer"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

Step2: Create another schema file Sales.xsd

<!-- to store the sales information with targetNamespace declared as tns:Sales-->
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="tns:Sales"
            elementFormDefault="unqualified">
    <xsd:complexType name="Sales">
        <xsd:sequence>
             <xsd:element name="Customer" type="xsd:string"/>
             <xsd:element name="Region" type="xsd:string"/>
             <xsd:element name="TransactionStatus" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

Step3: Import the two schema files in Catalog.xsd file

<!--using the Heterogeneous namespace design approach-->
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:b="tns:Books" xmlns:s="tns:Sales" xmlns:ns1="tns:Catalog" targetNamespace="tns:Catalog" elementFormDefault="unqualified">
	<xsd:import namespace="tns:Books" schemaLocation="Books.xsd"/>
	<xsd:import namespace="tns:Sales" schemaLocation="Sales.xsd"/>
	<xsd:element name="Catalog">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="Payment">
					<xsd:complexType>
						<xsd:sequence>
							<xsd:element name="CustomerID" type="xsd:integer"></xsd:element>
							<xsd:element name="PaymentType" type="xsd:string"></xsd:element>
							<xsd:element name="Currency" type="xsd:string"></xsd:element>
							<xsd:element name="ShippingAddress" type="xsd:string"></xsd:element>
						</xsd:sequence>
					</xsd:complexType>
				</xsd:element>
				<xsd:element name="Book" type="b:Book" maxOccurs="unbounded"/>
				<xsd:element name="Sales" type="s:Sales" maxOccurs="unbounded"/>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>

BAM Data read write from Dot net application

by Ali Raza Zaidi on September 20, 2011

You know that BAM is used to gather statistics from your BizTalk application. What you probably don’t know is that:

·          You can collect BAM data from your non-BizTalk applications such as external .NET components that BizTalk calls into.

·          Tracking profile editor (TPE) is not the only way to collect data you can use a set of APIs available in the Microsoft.BizTalk.Bam.EventObservation namespace to read and write directly into the BAMPrimaryImport database.

Check out some of the links here:

·          http://www.topxml.com/rbnews/BizTalk-BAM-activity/re-29195_Business-Activity-Monitoring–GenerateTypedBAMAPI-Tool.aspx

·          http://www.developer.com/net/net/article.php/11087_3587296_2

·          http://blogs.msdn.com/keithlim/archive/2006/02/02/522649.aspx

·          http://blogs.msdn.com/keithlim/archive/2006/03/08/545851.aspx   r

 

 

 

 

 

Original Article : http://geekswithblogs.net/benny/archive/2007/06/14/113219.aspx
 

 

Generic fault message exception handling

by Ali Raza Zaidi on September 19, 2011

 

In my current project, there are 50 operations on each port. It is very difficult and time consuming to create fault on every port operation and then add exception handler for every fault message.  This solution is not so comprehensive that if fault message is of different type what you made on each port

For example I selected “BTS.Soap_envelope_1__1.Fault on each operation,

than orchestration goes in suspended mode and process left uncompleted.

After too much search if found following exception type.

Microsoft.XLANGs.BaseTypes.UnexpectedMessageTypeException

 

Its works wonder if any fault message return my orchestration process is not break.

 

Pros: Normal exception caught and Orchestration completes its process.

Con: suspended instance of orchestration still visible at BizTalk admin with message “The instance completed without consuming all of its messages. The instance and its unconsumed messages have been suspended.”

Exploring the BizTalk 2010 schema Editor

by Ali Raza Zaidi on September 14, 2011

Whenever you create new schema in visual studio or open the exiting one in BizTalk application  you find similar window.

This screen shot is taken form  http://msdn.microsoft.com/en-us/library/aa559175%28v=bts.70%29.aspx.

[click to continue…]

What is BizTalk message Type ?

by Ali Raza Zaidi on September 12, 2011

All messages in BizTalk are represents in XML. One important aspect of all XML documents is its namespace. Briefly, a namespace allows you describe the Student (for example) in one way without affecting anyone else’s description, possible student can mean different things to other applications, Second important aspect of all XML document is the name of document root node.

For example namespace of student XML is

urn:schemas-BiztalkHQ-net:Student:mapcontext:1

and Root Node of Schema is

Student .

The combination of message namespace and name of root node are represented as:

 

urn:schemas-citrite-net:licensing:mapcontext:1#Student

The hash symbol (#) separates the namespace from the name of the root node.

BTSNTSvc.Exe.Config

by Ali Raza Zaidi on August 15, 2011

Just like web.config in asp.net and app.config in .net applicaiton.  BizTalk server stored configuration values in name value pair.

The File Name is “BTSNTSvc.Exe.Config”.

It is located at biztalk installation directory on you machines like

c:program files BizTalk Server 2006BTSNTSvc.exe.config

Sample config file look like this

<?xml version=”1.0″ ?>
<configuration>
<configSections>
<section name=”xlangs” type=”Microsoft.XLANGs.BizTalk.CrossProcess.XmlSerializationConfigurationSectionHandler, Microsoft.XLANGs.BizTalk.CrossProcess” />
</configSections>

<!– these settings are for BTS making HTTP/SOAP calls out, 2 concurrent connections is the default.
This should be in EVERY system where BTS is calling WebServices –>
<system.net>
<connectionManagement>
<add address=”*” maxconnection=”40″/>
</connectionManagement>
</system.net>
<runtime>
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<probing privatePath=”BizTalk Assemblies;Developer Tools;Tracking;Trackinginterop” />
</assemblyBinding>
</runtime>
<system.runtime.remoting>
<channelSinkProviders>
<serverProviders>
<provider id=”sspi” type=”Microsoft.BizTalk.XLANGs.BTXEngine.SecurityServerChannelSinkProvider,Microsoft.XLANGs.BizTalk.Engine” securityPackage=”ntlm” authenticationLevel=”packetPrivacy” />
</serverProviders>
</channelSinkProviders>
<application>
<channels>
<channel ref=”tcp” port=”0″ name=”">
<serverProviders>
<provider ref=”sspi” />
<formatter ref=”binary” typeFilterLevel=”Full”/>
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
<appSettings>
<add key=”Key1″ value=”Hello, World!” />
</appSettings>
<xlangs>
<Configuration><!– MaxThreshold – “Max time in memory an Orch will reside before dehydrat” MinThreshold – “Min time” –>
<Dehydration MaxThreshold=”1800″ MinThreshold=”1″ ConstantThreshold=”-1″>
<!– Currently, virtual memory can become a bottleneck on 32-bit machines due to unmanaged heap fragmentation, so you should throttle by this resource as well. –>
<VirtualMemoryThrottlingCriteria OptimalUsage=”900″” MaximalUsage=”1300″ IsActive=”true” />
<!– This is a useful criterion for throttling, but appropriate values depend on whether the box is being shared among servers. If the machine has a lot of RAM and is not being shared with other functions, then these values can be significantly increased.Optimal and maximal usage are in MB.–>
<PrivateMemoryThrottlingCriteria OptimalUsage=”50″ MaximalUsage=”350″ IsActive=”true” />
</Dehydration>
<Debugging ValidateSchemas=”true” ValidateAssemblies=”true” ExtendedLogging=”true” ValidateCorrelations=”false” />
<AppDomains AssembliesPerDomain=”10″>
<AppDomainSpecs>
<AppDomainSpec Name=”DemoDomain” SecondsIdleBeforeShutdown=”-1″ SecondsEmptyBeforeShutdown=”12000″ />
</AppDomainSpecs>
<ExactAssignmentRules>
<ExactAssignmentRule AssemblyName=”Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3a7d0586c62e754b” AppDomainName=”DemoDomain” />
</ExactAssignmentRules>
</AppDomains>
</Configuration>
</xlangs>
</configuration>

[click to continue…]

Configure BAM Portal Access in BizTalk 2010

by Ali Raza Zaidi on July 27, 2011

Currently I deployed the BAM definition, but It was surprise for me that my view did not appear in BAM portal.

I found that I did not grant access to BAM Portal. For this purpose I have to use BM.exe utility.  This tool is used for administer all things related to BAM, including deployment, permissions and alters.

The command line tool is located at the following location:

[BizTalk installation folder]Trackingbm.exe

Sample usage:
bm.exe add-account -AccountName:[DomainGroupName] -View:[BAM View]
or
bm.exe add-account -AccountName:[DomainSamAccountName] -View:[BAM View]