Wednesday, October 9, 2013

Resolved : Schema referenced by Map "XX" has been deleted. The local, cached The local, cached version of the BizTalk Server group configuration is out of date. You must refresh the BizTalk Server group configuration before making further changes.

Ok.so you got this error.

 
As the error message says, Map XX is referencing an schema which got removed from database, somehow. 
 
Before, solving the issue I would like to dig little deeper inside the BizTalk administration. Basically, BizTalk Admin console gets the most of the data (not all) from BizTalkMgmtDB. There are few set of tables which you need to know for solving this issue.


bt_MapSpec --> stores the metadata of BizTalk map
bts_Item --> store the items (map, schema, pipelines, orchestration etc) metadata(few not all)
bts_assembly --> stores the metadata of assemblies deployed in Biztalk
bts_sendport_transform --> stores the outbound map metadata, configured at send port
bts_receiveport_transform --> stores the inbound map metadata, configured at receive port.
bts_XMLShare --> store the metadata and content map,schemas etc.
(All the above tables are related with each other using ids,guids and names)
bt_DocumentSpec --> metadata of all type of schemas only

if you notice there are two columns in bt_MapSpec table has 2 special columns
indoc_docspec_name and outdoc_docspec_name, these two columns holds the fully qualified name of source schema and destination schema respectively.

Reason: possibly one of the schema got removed from dbo.bt_DocumentSpec table.

Resolution:
Option 1. Make the map unavailable (by deleting the map from bt_MapSpec, only which is causing the issue
Option 2. Make the missing schema available (by inserting the metadata of schema)
Option 3. Update the indoc_docspec_name/outdoc_docspec_name, whichever is missing, column of with the fully qualified name of document schema which is already available in BizTalkMgmtDb  

Any of the mentioned above option will solve the issue, I personally recommend option 3 as this cause minimum manual changes to the BizTalk database.

In BizTalk 2009, this issue is not much problematic as administrator load the map on when you are trying to reach the map and let you to delete the bztalk application (including problematic map). But in BizTalk 2010 you admin console almost fails at everystep what you are going to perform.

Note: before doing anything like this, there are suggestion or rather warning, do this only if know what exactly you are doing.

Saturday, March 24, 2012

Failed to Load Group : BizTalkMgmtDB : Issue while opening BizTalk administration console





We had two BizTalk servers added in a group and it is connecting to remote external sql server. Every thing was going fine.. life was coformtable.. until one fine day recieve a email marked Urgent and Subject :
with these two images.

One node of BizTalk Group was working fine and it was really a big relief as we can easily rule out any possible issue realted to SQL server.
So the problem was with the other node and there were numerous BizTalk errors logged by Host Instances, where host instance is trying to start but BizTalk is not able to make connection with the sql server.
Also, in Secuity log there were many audit failures of Windows filtering service.
As our BizTalk most instance were trying to establish the connection with SQL server but al incoming data packets were filtered by this service.Therefore, neither BizTalk Host Instances or BizTalk Administrator Console is able to connect to the SQL Server.



So following are the checklist:
1. Ping SQL server to verify if server is resolved properly.
2. Verify the name of SQL instance where BizTalkMgmtDB is place, there shouldn't be any typo mistake
3. SQL Server is running(not in my list but adding for the completion of blog)
4. Appropiate port (in this case UDP 1434) should be added in exception list or disable firewall(but definately check with server admin before disabling)

Following it the link(which saved my a$$): http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx


Good Luck :)

The Microsoft Distributed Transaction Coordinator (MS DTC) has cancelled the distributed transaction

There are many times I have encountered issues with DTC when working with BizTalk and SQL. In most of the cases either DTC isn't running or configured properly or some sort of security mismatch between the client and server DTC.

But recently, I seen some warings in eventlog wheneven I am enabling my SQL receive location and finally it gets disabled as SQL adapter didn't recover from the failures but this time the reason for these error wasn't any of them mentioned above.

Following are the warnings I was getting in windows eventlog:
HRESULT="0x80040e14" Description="The Microsoft Distributed Transaction Coordinator (MS DTC) has cancelled the distributed transaction." - Most of the time

Fewer times I got the following errors/ warning:
1. Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction
2. Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 1, current count = 0
3. Cannot roll back . No transaction or savepoint of that name was found

I was tired of watching Abort Transaction Counts on MSDTC :(

Root cause:
In our case, we are calling an wrapper stored procedure which houses the call to 6-7 other stored procedures and one of the Stored procedure was giving an error and transactions were not handled in the right manner.
Strange thing is that, this time the orginal error is getting suppressed because of further issues in transactions which made me really running like headless chinken to look where exactly the issue is. All I was looking at the possiblities near DTC and BizTalk.
It was SQL store procedure that was the real culprit.
So I've learnt its better to use the default isolation level(serializable) of SQL Adapter but if are overriding it in Stored procedure handle transactions very carefully and remember good exception handling mechanism is key of solving the issue faster.. really fast..:)
Gud Luck

Wednesday, June 1, 2011

Object reference not set to an instance of an object + BizTalk

Recently my team mate reported me an issue in his BizTalk application..
application does something like it gets the request from MSMQ then makes Database call get response from database and then write response to the response_MSMQ.

following is the error in eventlog:

Uncaught exception (see the 'inner exception' below) has suspended an instance of service (d18ebb96-bf15-bdd9-06f5-d2c07b2b4260)'.
The service instance will remain suspended until administratively resumed or terminated.
If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
InstanceId: 3e6974ee-1506-4eea-abcf-7c7b18cadf1b
Shape name:
ShapeId: 00000000-0000-0000-0000-000000000000
Exception thrown from: segment 19, progress 10
Inner exception: Object reference not set to an instance of an object.

Exception type: NullReferenceException
Source: ADDRECEIPTS_IN
Target Site: Microsoft.XLANGs.Core.StopConditions segment19(Microsoft.XLANGs.Core.StopConditions)
The following is a stack trace that identifies the location where the exception occured

at <>.segment19(StopConditions stopOn)
at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, S


There are two things I noticed :
1. When you look at the the Orchestration debugger for the the message it shows the message is sent to Database and no response is received fron SQL,, but certainly thats not the case as BizTalk has a concepts of persistance points, where it persists the state of orchestration at certain events of message flow, in my case it is the Send port by which I am sending message to database causes persistance.. and therefore it is showing me message flow till send shape. and after inspecting more a bit I concluded there in nothing wrong in response message from database. So definately something is going wrong between the sql send shape and the next persitance point.
So hereby is the problem with the code, where a .NET component is call and that piece of code is throwing this error. Hence, whenever you get this kind of error
a) make sure your are getting correct response message and it should'nt be null or something.
b) Look for the code there must be something which is screwing the stuff but deviating you from the issue root.

2) In case, I would have got this issue in first Activating Receive shape in orchestration, let me go to little back, when we create orchestration we define certain orchetration variable as well, as per the our business functionality.knowing the fact everything in BizTalk compiles to .NET code, If we try to assume an orchestration as class and Orchestration variables as class variables and when got this issue..Then I suggest to look at the code of constructors of orchestration variable defined types. there must be something wrong there.

Moral of the story: Handle exceptions properly and test exceptional handling, this is one of few things in programmers life which can soothe his burning @$$

Thursday, January 13, 2011

WMI Scripts + BizTalk

Recently, I moved into new BizTalk assigment and I was very happy but my happiness shattered completely as the Architecture was completely screwed up (I apologies, being 4+ yrs of exp, I don't hold qualification to comment anything on architecture but personall speaking it was screwed up :( ).

It was something like integrating 16 messages and without using any percentage of brain, people have created 16 orchestrations and that to in 16 different BizTalk projects. uff.. this made me remember my first year of career when I used to do POCs and its giving me the feeling they as well doing POCs and then moving their POCs to UAT server and finally to test server.

But truly speaking, they have a valid reason i.e. "Time constraint" so they haven't wasted single second for investigation and finally it ended-up in 12-14 hrs daily in office, effort shoot up by 200+%.

And this is not enough, to add further happiness I got the wonderful surprise on the next day itself, that the other guy is moving out and I have to carry forward the remaining development and production deployment. Soon I realized deployment will going to be real pain in a$$.



I left with 2 options: first resigning from the company, secondly to do something that will largely help me, I am not much worried for anything else.


So, I thought of doing deployment programatically i.e. using WMI.
Following are the task, I am going to achieve by deployment application:
1. Creating Host (3 Host)
2. Creating Host Instance (3 Host Instance)
3. Adding Send Handler (for 4 Adapters)
4. Adding Receive Handler (for 3 Adapters)
5. Creating BizTalk Application (4 New applications)
6. Adding Reference to applications (few numbers)
7. Installing BizTalk Assemblies (16+)
8. Loading Binding files (16+)
9. Few more minor activities.

Frankly speaking, If I have to do these many task I would rather prefer to quit my job and look for the new one.

The day I have finished my the coding for deployment, I cried tears of joy :)

WMI Application extensively uses:
System.Management namespace

So keeping this Bullshit aside let go straight to the code :

public partial class HostingTask
{
#region CONSTANTS
private const string WMI_Root = @"root\MicrosoftBizTalkServer";
private const string MSBTS_HostSetting = "MSBTS_HostSetting";
private const string MSBTS_ServerHost = "MSBTS_ServerHost";
private const string MSBTS_HostInstance = "MSBTS_HostInstance";
private const string MSBTS_AdapterSetting = "MSBTS_AdapterSetting";
private const string MSBTS_ReceiveHandler = "MSBTS_ReceiveHandler";
private const string MSBTS_SendHandler2 = "MSBTS_SendHandler2";
#endregion

private ManagementClass mgmtClass;
private ManagementObject mgmtObj;

#region AddHost Method :- This Method creates a Logical host in BizTalk Group
public void AddHost(BTHost host)
{
try
{

Console.WriteLine("Creating Host - " + host.HostName);
PutOptions options = new PutOptions();
options.Type = PutType.CreateOnly;
//create a ManagementClass object and spawn a ManagementObject instance
mgmtClass = new ManagementClass(WMI_Root, MSBTS_HostSetting, null);
if (!Exists(mgmtClass, "Name", host.HostName))
{
mgmtObj = mgmtClass.CreateInstance();
//set the properties for the Managementobject
mgmtObj["Name"] = host.HostName;
mgmtObj["HostType"] = host.HostType;
mgmtObj["NTGroupName"] = host.NTGroupName;
mgmtObj["AuthTrusted"] = host.AuthenticationTrusted;
mgmtObj["HostTracking"] = host.AllowHostTracking;
//create Host
mgmtObj.Put(options);
Console.WriteLine("Host - " + host.HostName + " - has been created successfully");
}
else
{
Console.WriteLine("BOSS.. Host - " + host.HostName + " - already in place.. why the hell you are wasting my time.");
}
}
catch (Exception ex){
Console.WriteLine("CreateHost - " + host.HostName + " - failed. I do expect people to do some part of his/her job. Anyway following is the exception message : " + ex);
throw;
}

}
#endregion


#region RemoveHost Method :- This Method Deletes a logical host from BizTalk Group
public void RemoveHost(string hostName)
{
try{
Console.WriteLine("Removing Host : " + hostName);
mgmtClass = new ManagementClass(WMI_Root, MSBTS_HostSetting, null);
if (Exists(mgmtClass, "Name", hostName))
{
mgmtObj = mgmtClass.CreateInstance();
mgmtObj["Name"] = hostName;
mgmtObj.Delete();
Console.WriteLine(hostName + "Host removed successfully");
}
else
{
}
}
catch {
throw;
}
}
#endregion


#region AddHostInstance :- This Method created the Host Instance on the physical server
public void AddHostInstance(BTHostInstance hostIns, string hostName)
{
try
{
if (hostIns.Server == null hostIns.Server == string.Empty)
{
hostIns.Server = Environment.MachineName;
}
Console.WriteLine("Creating Host Instance : " + hostName + "on Server : " + hostIns.Server);
//Creating instance of BizTalk Host.
mgmtClass = new ManagementClass(WMI_Root, MSBTS_ServerHost, null);
mgmtObj = mgmtClass.CreateInstance();
mgmtObj["ServerName"] = hostIns.Server;
mgmtObj["HostName"] = hostName;
//Map HostInstance to be created with the Host
mgmtObj.InvokeMethod("Map", null);
mgmtClass = new ManagementClass(WMI_Root, MSBTS_HostInstance, null);
mgmtObj = mgmtClass.CreateInstance();
mgmtObj["Name"] = "Microsoft BizTalk Server " + hostName + " " + hostIns.Server;
object[] objparams = new object[3];
objparams[0] = hostIns.Logon.Username;
objparams[1] = hostIns.Logon.Password;
objparams[2] = true;
//Create Host Instance
mgmtObj.InvokeMethod("Install", objparams);

Console.WriteLine("Host Instance " + mgmtObj["Name"] + " created.");
}
catch{
throw;
}
}
#endregion


#region RemoveHostInstance Method :- This Method deletes a Host Instance from the server and BizTalk Group
public void RemoveHostInstance(BTHostInstance hostIns, string hostName)
{
try
{
string hostInstanceName = "Microsoft BizTalk Server" + " " + hostName + " " + hostIns.Server;
Console.WriteLine("Removing Host Instance : " + hostInstanceName);
ManagementClass mgmtClass = new ManagementClass(WMI_Root, MSBTS_HostInstance, null);
ManagementObjectCollection hostInstanceCollection = mgmtClass.GetInstances();
ManagementObject mgmtObj = null;
foreach (ManagementObject instance in hostInstanceCollection)
{
if (instance["Name"].ToString().ToUpper() == hostInstanceName.ToUpper())
{
mgmtObj = instance;
}
}
if (mgmtObj == null)
return;
if (mgmtObj["HostType"].ToString() != "2" && mgmtObj["ServiceState"].ToString() == "4")
{
//If HostInstance is not stopped.. Stop it or is instance of type IsolatedHost
mgmtObj.InvokeMethod("Stop", null);
}
//Remove Host Instance
mgmtObj.InvokeMethod("UnInstall", null);
ManagementClass svrHostClass = new ManagementClass(WMI_Root, MSBTS_ServerHost, null);
ManagementObject svrHostObject = svrHostClass.CreateInstance();
svrHostObject["ServerName"] = hostIns.Server;
svrHostObject["HostName"] = hostName;
//Unmap Host-instance from Host
svrHostObject.InvokeMethod("UnMap", null);
Console.WriteLine("Host Instance : " + hostInstanceName + " removed Sucessfully");
}
catch
{
throw;
}
}
#endregion


#region AddSendHandler Method :- This method Adds the send handler for an Adapter
public void AddSendHandler(string adapterName, string handler)
{
try
{
Console.WriteLine("Adding Send Handler : " + handler + " to " + adapterName + " Adapter.");
ManagementClass mgmtClass = new ManagementClass(WMI_Root, MSBTS_SendHandler2,null);
if (!Exists(mgmtClass, "HostName", handler, "AdapterName", adapterName))
{
mgmtObj = mgmtClass.CreateInstance();
mgmtObj.SetPropertyValue("AdapterName", adapterName);
mgmtObj.SetPropertyValue("HostName", handler);
mgmtObj.Put();
Console.WriteLine("Send Handler : " + handler + " added to " + adapterName + " Adapter.");
}
else
{
}
}
catch
{
throw;
}
}
#endregion


#region RemoveSendHandler Method :- This method removes the send handler for an Adapter
public void RemoveSendHandler(string adapterName, string handler)
{
try
{

Console.WriteLine("Removing Send Handler : " + handler + " from " + adapterName + " Adapter.");
mgmtClass = new ManagementClass(WMI_Root, MSBTS_SendHandler2, null);
if (Exists(mgmtClass, "HostName", handler, "AdapterName", adapterName))
{
mgmtObj = mgmtClass.CreateInstance();
mgmtObj.SetPropertyValue("AdapterName", adapterName);
mgmtObj.SetPropertyValue("HostName", handler);
mgmtObj.Delete();
Console.WriteLine("Send Handler : " + handler + " removed from " + adapterName + " Adapter.");
}
else
{

}
}
catch
{
throw;
}
}
#endregion


#region AddReceiveHandler Method :- This method Adds the receive handler for an Adapter
public void AddReceiveHandler(string adapterName, string handler)
{
try
{
Console.WriteLine("Adding Receive Handler : " + handler + " to " + adapterName + " Adapter.");
mgmtClass = new ManagementClass(WMI_Root, MSBTS_ReceiveHandler, null);
if (!Exists(mgmtClass, "HostName", handler, "AdapterName", adapterName))
{
mgmtObj = mgmtClass.CreateInstance();
mgmtObj.SetPropertyValue("AdapterName", adapterName);
mgmtObj.SetPropertyValue("HostName", handler);
mgmtObj.Put();
Console.WriteLine("Receive Handler : " + handler + " added to " + adapterName + " Adapter.");
}
else
{
}
}
catch
{
throw;
}
}
#endregion


#region RemoveReceiveHandler Method :- This Method removes the receive handler for an Adapter
public void RemoveReceiveHandler(string adapterName, string handler)
{
Console.WriteLine("Removing Receive Handler : " + handler + " from " + adapterName + " Adapter.");
mgmtClass = new ManagementClass(WMI_Root, MSBTS_ReceiveHandler, null);
if (Exists(mgmtClass, "HostName", handler, "AdapterName", adapterName))
{
mgmtObj = mgmtClass.CreateInstance();
mgmtObj.SetPropertyValue("AdapterName", adapterName);
mgmtObj.SetPropertyValue("HostName", handler);
mgmtObj.Delete();
Console.WriteLine("Receive Handler : " + handler + " added to " + adapterName + " Adapter.");
}
else
{
}
}
#endregion


#region Exists Method :- This method checks the presence of Management object
private bool Exists(ManagementClass cls, string key , string val)
{
ManagementObjectCollection objcoll = cls.GetInstances();
foreach(ManagementObject obj in objcoll)
{
if (obj[key].ToString().ToUpper() == val.ToUpper())
return true;
}
return false;
}
#endregion


#region Exists Method :- This method checks the presence of Management object
private bool Exists(ManagementClass cls, string key, string val,string key1, string val1)
{
ManagementObjectCollection objcoll = cls.GetInstances();
foreach (ManagementObject obj in objcoll)
{
if (obj[key].ToString().ToUpper() == val.ToUpper() && obj[key1].ToString().ToUpper() == val1.ToUpper())
return true;
}
return false;
}
#endregion
}

Sunday, August 8, 2010

Info: Network Stream Length is not available at Server to read buffer from Client

In general, CLIENT writes the array of bytes or buffer and SERVER reads this buffer, but the problem is, lets say CLIENT writes X length of Array of bytes but as Network stream does not support length property therefore SERVER has no idea that how many bytes are written by CLIENT, therefore at server level its quite difficult to initialize the buffer to read. So, the best approach I think is to read data accurately without data loss , it to Read data in chunks till the end to Stream is reached in this way we can ensure the full data read also can keep the memory usage flat.

CODE SAMPLE :

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;


namespace TCPServer
{
class Program
{
static void Main(string[] args)
{
try
{
IPAddress ipAd = IPAddress.Parse("192.168.1.7");
// use local m/c IP address, and
// use the same in the client

// Initializes the Listener
TcpListener myList = new TcpListener(ipAd, 8002);

// Start Listeneting at the specified port
myList.Start();
Console.WriteLine("The server is running at port 8002...Waiting for a connection.....");

TcpClient cl = myList.AcceptTcpClient();
Console.WriteLine("Connection accepted");

Stream ns = cl.GetStream();
byte[] b = Utilities.ReadFully(ns, 0);

Console.WriteLine("Recieved...");
TRGRequest tTRGRequest = (TRGRequest)Utilities.Deserialize(b);

#region Send Ack

ASCIIEncoding asen = new ASCIIEncoding();
byte[] ack = asen.GetBytes("The string was recieved by the server.");
ns.Write(ack, 0, ack.Length);
Console.WriteLine("\nSent Acknowledgement");

#endregion

cl.Close();
ns.Close();
myList.Stop();
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}
}
}


public class Utilities
{
public static object Deserialize(byte[] bytes)
{
BinaryFormatter bFormatter = new BinaryFormatter();
using (MemoryStream strm = new MemoryStream())
{
strm.Write(bytes, 0, bytes.Length);
strm.Seek(0, SeekOrigin.Begin);
return (object)bFormatter.Deserialize(strm);
}
}



///
/// Reads data from a stream until the end is reached. The
/// data is returned as a byte array. An IOException is
/// thrown if any of the underlying IO calls fail.
///

/// The stream to read data from
/// The initial buffer length
public static byte[] ReadFully(Stream stream, int initialLength)
{
// If we've been passed an unhelpful initial length, just
// use 32K.
if (initialLength < 1)
{
initialLength = 32768;
}

byte[] buffer = new byte[initialLength];
int read = 0;

int chunk;
while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0)
{
read = read + chunk;

// If we've reached the end of our buffer, check to see if there's
// any more information
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();

// End of stream? If so, we're done
if (nextByte == -1)
{
return buffer;
}

// Nope. Resize the buffer, put in the byte we've just
// read, and continue
byte[] newBuffer = new byte[buffer.Length * 2];
Array.Copy(buffer, newBuffer, buffer.Length);
newBuffer[read] = (byte)nextByte;
buffer = newBuffer;
read = read + 1;
}
else
{
//return buffer;
// Buffer is now too big. Shrink it.
byte[] ret = new byte[read];
Array.Copy(buffer, ret, read);
return ret;
}

}
byte[] ret1 = new byte[read];
Array.Copy(buffer, ret1, read);
return ret1;
}
}
}

Info : TCP/IP- Network Stream understanding in Client Server Architecture

Well, I am enroute for writing cutom adapter for BizTalk i.e. TCPAdapter, as I dont have much knowledge of this protocol, and very I am not going to attain full knowledge on TCP as I always leave some scope of learning of future.
So, let me share my partial knowledge with you guys , please correct me if I am wrong and feel free to extend this post with your outstanding knowledge.
Earlier when I created some .NET applications which interacts with each other by using .NET remoting, ok let me expand a bit, 2 different applications that means atleast in 2 different Appdomains (if they are same Appdomains we dont need remoting we just need to reference assmbly and invokes its method or whatever crap we want to do..) and if we want to these 2 appliations communicate with each other there comes .NET remoting (Now again we can use web services or HTTP to make them communicate but for now lets park them aside, we will keep our focus on TCP) then we used to do marshalling (MBR or MBV).
Something like, Client application makes call to Proxy (again, Tansparent proxy which is something like superset of real proxy) and this proxy and then the object is formatted by suitable formatter (in case of TCP , its Binary formatter and in case of HTTP its SOAP Formatter ) and then formatted object is pushed to channel and then at server application this formmated object is re-formatted back to the original shape nad then get access to remote object or application or whatever.
Dont get confused by formatted object, its basically a serialized object or better Binary serialized object or more specifically an array of bytes, these bytes passes through channel and then at server application Deserialized back to the original object from the array of bytes. Great RIGHT??
I guess NO, in this case you need share your class definitions or object model with client as we were doing since ages while doing web services development as we share WSDL files with client application.

When I was very new to BizTalk, I was very afraid of Streams and BizTalk uses streams as max a possible at adapters , at pipelines, at Maps etc etc.. therefore I was afraid of BizTalk too.
But later on I came to know BizTalk is design to work with any message formats whether it is XML or flat files or binary or anything you can can think of. So, with no doubt Streams was the only choice to work with BizTalk.
So, I thought of creating Client - Server applications which will communicate via TCP and share messages in form of streams.
So in short, SERVER should be able to LISTEN at one port, CLIENT will connect to SERVER then CLIENT creates an object and Serializes this object in bytes and then CLIENT will Send these bytes to SERVER which receives these bytes and then Deserializes it back to the object.
Note: In these extending the functionalities as I am formatting and reformatting objects i.e. Serialization and Deserialization explicitly, Earlier it was done automatically before by the applications at the boundaries of communication channel.

Rather then, sharing the hell lot of crap story lets go ahead with the code.
(when connecion is established between CLIENT and SERVER, resources are allocated for communication which are generally termed as Channel, and in this code Network streams is used to read and write bytes at both client and server, Code itself speaks everything and its working but not that beautiful) , If you people have any doubts or correction please let me know

CLIENT CODE:

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;


namespace TCPClient
{
class Program
{
static void Main(string[] args)
{
try
{
TcpClient tcpclnt = new TcpClient();
Console.WriteLine("Connecting.....");

tcpclnt.Connect("192.168.1.7", 8002);
// use the ipaddress as in the server program

Console.WriteLine("Connected");

TRGRequest req = new TRGRequest();
req.Packet = "10255PatientTransferrdkhanycb3urhg55p3khu1br#633557240738841151TRGIP1ADTA01388falsetrue1200221falseRJRCLEBAE1CSCUBedZMQCKZ2009-02-05T12:47:332009-02-05T12:47:33G2009-02-05T12:47:33TBQQCDZR395473151RHQCDZR395473151RHGMC ID numberMPKGMC224210852RLNATGP IDnumberMPKNATGP224210852RLNLVCUIAMNLVCUIAMOFKAMTJ227166764OFKAMTJ227166764WYUBB2953CNQSZPALMNKZH3342INUQLXXMHVXU791P1408EVU9100J2883TJY648582865SHH1513G2962DEHPTOVKGJGPTOVKGJGNTFTUYNTFTUYPublicitycodeProtectionindicatorDJTOPXCXUOQJJINNBOVDJZE2009-02-05T12:47:33DfalseZX2009-02-05T12:47:33ZTQBDFNFOPDZY
PPUZVG8265K6561HGYEW
EHDZD806C9683HNStrueI4642Q1141
TXUJS1111U4413ZTXUJS1111U4413ZCC_IDTYPASNBR123RVYMRLRIBNOT FACILNVK4763I6240KAIUUB2009-02-05T12:47:33G1444L7512MVYT
PPUZVG8265K6561HGYEW
PPUZVG8265K6561HGYEW
HNSI4642Q1141HNSI4642Q1141HNStrueI4642Q1141HNStrueI4642Q1141HNStrueHNStrue
IUUB2009-02-05T12:47:33G1444L7512MVYT
PPUZVG8265K6561HGYEW
PPUZVG8265K6561HGYEW
HNSI4642Q1141HNSI4642Q1141HNStrueI4642Q1141HNStrueI4642Q1141HNStrueHNStrue
VUDE880923590D1585Q3802AIW5205RABRS9268W1559TFHVNT9783G9871EIXQJMGPTOVKGJGPTOVKGJGNTFTUYNTFTUYPublicitycodeProtectionindicatorEXWBSJBWJJDJTO
YUT6391QQAVZWTBWZVZWTBWZRUQSQSEX6115SZVZWTBWZVZWTBWZGO
";
req.Metadata = new Metadata();
req.Metadata.AppStackVersion = "2.630.0.0";

Stream stm = tcpclnt.GetStream();

byte[] ba = Utilies.Serialize(req);

Console.WriteLine("Transmitting.....");

stm.Write(ba, 0, ba.Length);

byte[] bb = new byte[100];
int k = stm.Read(bb, 0, 100);

for (int i = 0; i < bformatter =" new" ms =" new" ipad =" IPAddress.Parse(" mylist =" new" cl =" myList.AcceptTcpClient();" ns =" cl.GetStream();" b =" Utilities.ReadFully(ns," ttrgrequest =" (TRGRequest)Utilities.Deserialize(b);" asen =" new" ack =" asen.GetBytes(" bformatter =" new" strm =" new">
/// Reads data from a stream until the end is reached. The
/// data is returned as a byte array. An IOException is
/// thrown if any of the underlying IO calls fail.
///
/// The stream to read data from
/// The initial buffer length
public static byte[] ReadFully(Stream stream, int initialLength)
{
// If we've been passed an unhelpful initial length, just
// use 32K.
if (initialLength < initiallength =" 32768;" buffer =" new" read =" 0;" chunk =" stream.Read(buffer,"> 0)
{
read = read + chunk;

// If we've reached the end of our buffer, check to see if there's
// any more information
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();

// End of stream? If so, we're done
if (nextByte == -1)
{
return buffer;
}

// Nope. Resize the buffer, put in the byte we've just
// read, and continue
byte[] newBuffer = new byte[buffer.Length * 2];
Array.Copy(buffer, newBuffer, buffer.Length);
newBuffer[read] = (byte)nextByte;
buffer = newBuffer;
read = read + 1;
}
else
{
//return buffer;
// Buffer is now too big. Shrink it.
byte[] ret = new byte[read];
Array.Copy(buffer, ret, read);
return ret;
}

}
byte[] ret1 = new byte[read];
Array.Copy(buffer, ret1, read);
return ret1;
}
}
}


OBJECT MODEL of TRGRequest :
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//

//------------------------------------------------------------------------------

using System.Xml.Serialization;
using System.Runtime.Serialization;

//
// This source code was auto-generated by xsd, Version=2.0.50727.42.
//


///
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class TRGRequest {

private string packetField;

private Metadata metadataField;

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string Packet {
get {
return this.packetField;
}
set {
this.packetField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute("Metadata", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Metadata Metadata {
get {
return this.metadataField;
}
set {
this.metadataField = value;
}
}
}

///
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class Metadata {

private string sendingOrgIDField;

private string sendingSystemField;

private string receivingOrgIDField;

private string receivingSystemField;

private string domainField;

private string messageTypeField;

private string messageIDField;

private string iXMLVersionField;

private string appStackVersionField;

private string machineAddrField;

private string serviceNameField;

private string sessionIDField;

private string replayFlagField;

private string messageSystemField;

private string originalProductionTypeField;

private string originalProductionNameField;

private string currentProductionNameField;

private string finalProductionTypeField;

private string finalProductionNameField;

private string directionField;

private string currentFormatField;

private string statusField;

private string errorCodeField;

private string errorStringField;

private string dateCreatedField;

private string contentTypeField;

private string refToMessageIDField;

private string custom1Field;

private string custom2Field;

private string custom3Field;

private string mSATextField;

private string patientIDField;

private string patientPrimaryFacilityField;

private string patientPrimaryCareProviderField;

private string patientClassField;

private string assignedPatientLocationField;

private string preAdmitNumberField;

private string visitIDField;

private string placerOrderNumberField;

private string placerGroupNumberField;

private string orderStatusField;

private string enteredByField;

private string orderingProviderField;

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string SendingOrgID {
get {
return this.sendingOrgIDField;
}
set {
this.sendingOrgIDField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string SendingSystem {
get {
return this.sendingSystemField;
}
set {
this.sendingSystemField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string ReceivingOrgID {
get {
return this.receivingOrgIDField;
}
set {
this.receivingOrgIDField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string ReceivingSystem {
get {
return this.receivingSystemField;
}
set {
this.receivingSystemField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string Domain {
get {
return this.domainField;
}
set {
this.domainField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string MessageType {
get {
return this.messageTypeField;
}
set {
this.messageTypeField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string MessageID {
get {
return this.messageIDField;
}
set {
this.messageIDField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string iXMLVersion {
get {
return this.iXMLVersionField;
}
set {
this.iXMLVersionField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string AppStackVersion {
get {
return this.appStackVersionField;
}
set {
this.appStackVersionField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string MachineAddr {
get {
return this.machineAddrField;
}
set {
this.machineAddrField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string ServiceName {
get {
return this.serviceNameField;
}
set {
this.serviceNameField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string SessionID {
get {
return this.sessionIDField;
}
set {
this.sessionIDField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string ReplayFlag {
get {
return this.replayFlagField;
}
set {
this.replayFlagField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string MessageSystem {
get {
return this.messageSystemField;
}
set {
this.messageSystemField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string OriginalProductionType {
get {
return this.originalProductionTypeField;
}
set {
this.originalProductionTypeField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string OriginalProductionName {
get {
return this.originalProductionNameField;
}
set {
this.originalProductionNameField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string CurrentProductionName {
get {
return this.currentProductionNameField;
}
set {
this.currentProductionNameField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string FinalProductionType {
get {
return this.finalProductionTypeField;
}
set {
this.finalProductionTypeField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string FinalProductionName {
get {
return this.finalProductionNameField;
}
set {
this.finalProductionNameField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string Direction {
get {
return this.directionField;
}
set {
this.directionField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string CurrentFormat {
get {
return this.currentFormatField;
}
set {
this.currentFormatField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string Status {
get {
return this.statusField;
}
set {
this.statusField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string ErrorCode {
get {
return this.errorCodeField;
}
set {
this.errorCodeField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string ErrorString {
get {
return this.errorStringField;
}
set {
this.errorStringField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string DateCreated {
get {
return this.dateCreatedField;
}
set {
this.dateCreatedField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string ContentType {
get {
return this.contentTypeField;
}
set {
this.contentTypeField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string RefToMessageID {
get {
return this.refToMessageIDField;
}
set {
this.refToMessageIDField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string Custom1 {
get {
return this.custom1Field;
}
set {
this.custom1Field = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string Custom2 {
get {
return this.custom2Field;
}
set {
this.custom2Field = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string Custom3 {
get {
return this.custom3Field;
}
set {
this.custom3Field = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string MSAText {
get {
return this.mSATextField;
}
set {
this.mSATextField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string PatientID {
get {
return this.patientIDField;
}
set {
this.patientIDField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string PatientPrimaryFacility {
get {
return this.patientPrimaryFacilityField;
}
set {
this.patientPrimaryFacilityField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string PatientPrimaryCareProvider {
get {
return this.patientPrimaryCareProviderField;
}
set {
this.patientPrimaryCareProviderField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string PatientClass {
get {
return this.patientClassField;
}
set {
this.patientClassField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string AssignedPatientLocation {
get {
return this.assignedPatientLocationField;
}
set {
this.assignedPatientLocationField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string PreAdmitNumber {
get {
return this.preAdmitNumberField;
}
set {
this.preAdmitNumberField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string VisitID {
get {
return this.visitIDField;
}
set {
this.visitIDField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string PlacerOrderNumber {
get {
return this.placerOrderNumberField;
}
set {
this.placerOrderNumberField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string PlacerGroupNumber {
get {
return this.placerGroupNumberField;
}
set {
this.placerGroupNumberField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string OrderStatus {
get {
return this.orderStatusField;
}
set {
this.orderStatusField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string EnteredBy {
get {
return this.enteredByField;
}
set {
this.enteredByField = value;
}
}

///
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string OrderingProvider {
get {
return this.orderingProviderField;
}
set {
this.orderingProviderField = value;
}
}
}

Thursday, August 5, 2010

Error details: The published message could not be routed because no subscribers were found.

Error details: The published message could not be routed because no subscribers were found. This error occurs if the subscribing orchestration or send port has not been enlisted, or if some of the message properties necessary for subscription evaluation have not been promoted. Please use the Biztalk Administration console to troubleshoot this failure.

Reason : As simple as, BizTalk engine is not able to find subscriptions for the incoming message.
under the hood : while publishing the message in BizTalkMsgDB [SPOOL] table. Biztalk engine executes many stored procedures, but the point in focus here are (1). bts_InsertProperty [this SP is executed for each context property of Message] (2).bts_FindSubscriptions [pass batch id as parameter and queries Subscription, ConvoySetInstance and many predicates table and gets subscription Id] (3).bts_InsertMessage [subscrition Id is passed as parameter, commits message in Spool table and call various SPs] , (4).int_EvaluateSuscription [passed subscription Id as parameter and then message reference is inserted into respective queue].

So, as far as entry(row) is there in Subscription table it may passed to the next level and may we will not get this error.
Resolution : 1. Check the Orchestration or SendPort is Enlisted which is going the message
2. If the input message is XML then use XMLReceivePipeline, as this pipeline contains XMLDisassembler components which populates MessageType context property which is used for routing xml messages.

Error : Finding the document specification by message type failed. Verify the schema deployed properly.

I am a BizTalk but recently got interviewed from Microsoft, for support role and they are looking people for BizTalk Administration role. finally failed in 3rd round or interview.
Since then I started learning BizTalk from administration .

Recently I was building an application which polls a SQL Table at regular time interval, and get records from the table and feed these request to BizTalk Engine, where BizTalk Orchestration is subscribed to these MessageTypes and carry out rest of the processing.
Being a Developer, I have always used the simplest way for deploying an application, "Right Click to solution and select Deploy" as expected everything goes fine all artifacts got deployed in default Application "BizTalk Application 1".
Then I decided to do this to deploy solution in different "Application", I did necessary configuration and fired a message. Then I got the error as mentioned as title of this post.
Reason is very clear "The schemas was deployed in BizTalk Application 1", then I moved the neceassry schemas in new application" then it worked.
From the Default application, select the artifacts -> right click -> then Select move to application.