Monday, December 17, 2012

Problem Enlisting Send Port

Error:
Unable to communicate with MessageBox BizTalkMsgBoxDb Error Code: 0x8004d00e.
etc.

Solution:


Sometime it happens that you edited the binding file and due to encoding issue of visual studio while saving whitespaces created at starding and ending of FILTER element.
Like
<Filter>
&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;Filter xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance
" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;Group&gt;
&lt;Statement Property="BTS.MessageType" Operator="0" Value="
http://Dummy#DummyH" /&gt;
&lt;/Group&gt;
&lt;/Filter&gt;

</Filter>
So, update it to as below

<Filter>
&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;Filter xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;Group&gt;
&lt;Statement Property="BTS.MessageType" Operator="0" Value="
http://Dummy#DummyH" /&gt;
&lt;/Group&gt;
&lt;/Filter&gt;
</Filter>


HopeFully it should work out for you as worked for me.


Regards
Kundan

 

Friday, November 9, 2012

BizTalk Server 2013

Monday, September 17, 2012

BizTalk 2006(NOT R2) integration with MOSS 2007 using WSS adapter

Problem Statement: As per microsoft guidlines BizTalk 2006 R2 can only do the communication with MOSS 2007 with WSS adapter.
But BizTalk Server 2006 (NOT R2) can't Integrate with MOSS 2007 using WSS adapter.

Solution: By following the below workaround we can do the set-up for BizTalk 2006 to MOSS 2007 Integration using WSS adapter.

BizTalk 2006 integration with MOSS 2007 using WSS Adapter.
1.0          Assumptions
·        BizTalk Server and MOSS is already installed on respective machines
·        BizTalk Server and MOSS server are on different machine.
·        BizTalk Server version is 2006 (not R2)
·        MOSS Server is 2007 (with WSS 3.0)
2.0          Setup on BizTalk Application Server
Following are the steps for setting up the BizTalk Application server, after BizTalk Server 2006 is installed.
1.     Download WSS 2.0, and installed it.
2.     Re-Run the BizTalk Installation (from CD, or from saved setup).
3.     Inside Additional components only select WSS Adapter for BizTalk., and install it.
4.     Run BizTalk configuration wizard, select WSS Adapter and select the Default Site, and configure the WSS adapter for BizTalk.
5.     Inside Default Site, webservice is been created BTSharePointAdapterWS , go to its location , copy and save it somewhere.
6.     Download WSS 3.0, and installed it on same machine.
7.     WSS 3.0 installation will create a site in IIS, go to that site and Add Virtual Directory, and provide the path of BTSharePointAdapterWS.
i.e. C:\Program Files\Microsoft BizTalk Server 2006\Business Activity Services\BTSharePointAdapterWS

Open Web.config of BTSharePointAdapterWS

Paste the following section into the web.config file, configuration section and save the file
 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.SharePoint"
                          publicKeyToken="71e9bce111e9429c" />
        <bindingRedirect oldVersion="11.0.0.0"
                         newVersion="12.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

8.     Restart IIS and BizTalk Server host instances.
9.     Remove WSS 2.0.
10.                         Restart IIS and BizTalk Server host instances.

3.0          Setup on MOSS Server
Following are the steps to be carried out on MOSS  server, after
1.     Download WSS 2.0, and installed it.
2.     Re-Run the BizTalk Installation (from CD, or from saved setup).
3.     Inside Additional components only select WSS Adapter for BizTalk, and install it.
4.     Remove WSS 2.0.
5.     Go to MOSS website and
(copy BTSharePointAdapterWS from BizTalk Server to MOSS Server at  C:\Program Files\Microsoft BizTalk Server 2006\Business Activity Services\ )
Add Virtual Directory, and provide the path of BTSharePointAdapterWS.
i.e. C:\Program Files\Microsoft BizTalk Server 2006\Business Activity Services\BTSharePointAdapterWS

Open Web.config of BTSharePointAdapterWS

Paste the following section into the web.config file, configuration section and save the file
 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.SharePoint"
                          publicKeyToken="71e9bce111e9429c" />
        <bindingRedirect oldVersion="11.0.0.0"
                         newVersion="12.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

6.     Restart IIS and BizTalk Server host instances.


BizTalk WCF Custom Service Behaviour

WCF with BizTalk comes with a great features. There are lot of thing we can do this, we just need to discover them. As it is not too old , so lots of things we can't find on web. But belive me it is much more than what do we think.

I am just sahring its one of the feature with you.

Creating WCF-Custom Service Behaviour


 Problem statement: Suppose you want to create a BizTalk receive location (of WCF Webservice), And once you receive a requent on this port , immediately you need to send a Response back (with-in same time syncronously) with some kind of XML type but populating some of the response xml fields from Input message fields.

Note: Solve above problem without using Orchestration.

Solution:

We can able to solve above problem without using an Orchestration , but creating a WCF-Custom Service Behaviour.

Setps.
1. Create a BizTalk Server Recevie location of WCF-CusomIsolated (Or can be WCF-Custom , host it on In-Process host in this case).
2.Add Class library Project and Add three classess.

a. CustomTechKundanBTSResponseProviderBehaviorExtensionElement.cs
//Start CustomTechKundanBTSResponseProviderBehaviorExtensionElement.cs
using System;
using System.Collections.Generic;using System.Text;using System.ServiceModel.Configuration;using System.Configuration;using System.Xml.Schema;using System.Xml;namespace Kundan.Integrations.WCF{

public class CustomTechKundanBTSResponseProviderBehaviorExtensionElement : BehaviorExtensionElement{public CustomTechKundanBTSResponseProviderBehaviorExtensionElement(){
}

public override Type BehaviorType{

get{return typeof(CustomTechKundanBTSResponseProviderServiceBehavior);}
}

protected override object CreateBehavior(){

return new CustomTechKundanBTSResponseProviderServiceBehavior(SuccesResponse, ErrorResponse, MaxLengthFaultMessage);}
[
ConfigurationProperty("SuccesResponse", DefaultValue = "", IsRequired = false)]
public string SuccesResponse{

get { return (string)base["SuccesResponse"]; }
set { base["SuccesResponse"] = value; }}
[
ConfigurationProperty("ErrorResponse", DefaultValue = "", IsRequired = false)]
public string ErrorResponse{

get { return (string)base["ErrorResponse"]; }
set { base["ErrorResponse"] = value; }}
[
ConfigurationProperty("MaxLengthFaultMessage", DefaultValue = "", IsRequired = false)]
public int? MaxLengthFaultMessage{

get { return (int?)base["MaxLengthFaultMessage"]; }
set { base["MaxLengthFaultMessage"] = value; }}
}
}
//End: CustomTechKundanBTSResponseProviderBehaviorExtensionElement.cs
b.CustomTechKundanBTSResponseProviderMessageInspector.cs
using System;using System.Collections.Generic;using System.Text;using System.ServiceModel;using System.ServiceModel.Channels;using System.ServiceModel.Dispatcher;using System.Xml;using System.Xml.XPath;namespace Kundan.Integrations.WCF{

public class CustomTechKundanBTSResponseProviderMessageInspector : IDispatchMessageInspector{String _succesResponse = null;
String _errorResponse = null;
int? _maxLengthFaultString;
bool _emptyMessage;
XPathDocument Requestdocument = null;
XmlDocument xmldoc = null;

public CustomTechKundanBTSResponseProviderMessageInspector(String succesResponse, String errorResponse, int? maxLengthFaultString){
_succesResponse = succesResponse;
_errorResponse = errorResponse;
_maxLengthFaultString = maxLengthFaultString;
}
#region IDispatchMessageInspector Members
object IDispatchMessageInspector.AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext){
_emptyMessage = request.IsEmpty;

xmldoc =
new XmlDocument();xmldoc.Load(request.GetReaderAtBodyContents());
System.Diagnostics.
EventLog.WriteEntry("KundanBTS WCF compo", xmldoc.InnerXml);

Message message = Message.CreateMessage(request.Version, null, new XmlNodeReader(xmldoc));
//copy back the original headers and properties to the new messagemessage.Headers.CopyHeadersFrom(request.Headers);
message.Properties.CopyProperties(request.Properties);
//assign the new message to the referenced request messagerequest = message;return null;}


void IDispatchMessageInspector.BeforeSendReply(ref Message reply, object correlationState){
System.IO.
StringReader stringreader = null;System.Diagnostics.
EventLog.WriteEntry("KundanBTS WCF compo", "Inside Reply");
String sErrorResponse = "";
String sSuccesResponse = "";
if (!_emptyMessage){

if (reply.IsFault){
System.Diagnostics.
EventLog.WriteEntry("KundanBTS WCF compo", "Inside Error");
//create the error message if the property is setif (_errorResponse != null && _errorResponse.Length > 0){

if (_errorResponse.Contains("%providerID%")){

string strProvider = null;
string strRequester = null;
XPathNavigator navigator = xmldoc.CreateNavigator();
XPathNodeIterator Providernode = navigator.Select("//*[local-name()='providerID']");
XPathNodeIterator Requesternode = navigator.Select("//*[local-name()='RequesterD']");
while (Providernode.MoveNext()){
strProvider = Providernode.Current.Value;
}

while (Requesternode.MoveNext()){
strRequester =
"KundanBTS_" + Requesternode.Current.Value;}
sErrorResponse = _errorResponse;
sErrorResponse = sErrorResponse.Replace(
"%providerID%", strProvider);sErrorResponse = sErrorResponse.Replace(
"%RequesterID%", strRequester);
stringreader =
new System.IO.StringReader(sErrorResponse);
}

else{return;}
}
}

else{//create the succes message if the property is setSystem.Diagnostics.EventLog.WriteEntry("KundanBTS WCF compo", "Inside Success");
string strProvider = null;
string strRequester = null;
XPathNavigator navigator = xmldoc.CreateNavigator();
XPathNodeIterator Providernode = navigator.Select("//*[local-name()='providerID']");
XPathNodeIterator Requesternode = navigator.Select("//*[local-name()='RequesterID']");
while (Providernode.MoveNext()){
strProvider = Providernode.Current.Value;
}

while (Requesternode.MoveNext()){
strRequester = Requesternode.Current.Value;
}
sSuccesResponse = _succesResponse;

sSuccesResponse = sSuccesResponse.Replace(
"%providerID%", strProvider);sSuccesResponse = sSuccesResponse.Replace(
"%RequesterID%", strRequester);stringreader =
new System.IO.StringReader(sSuccesResponse);


}

XmlTextReader xmlreader = new XmlTextReader(stringreader);

// Create new message Message newMsg = Message.CreateMessage(reply.Version, null, xmlreader);
// Close the original message and return new messagereply.Close();
reply = newMsg;
}
}
#endregion}
}

c.CustomTechKundanBTSResponseProviderServiceBehavior.cs

using System;using System.Collections.Generic;using System.Text;using System.ServiceModel.Description;using System.Xml.Schema;using System.ServiceModel;using System.ServiceModel.Dispatcher;using System.ServiceModel.Channels;namespace Kundan.Integrations.WCF{

public class CustomTechKundanBTSResponseProviderServiceBehavior : IServiceBehavior{String _succesResponse = null;
String _errorResponse = null;
int? _maxLengthFaultString;
public CustomTechKundanBTSResponseProviderServiceBehavior(String succesResponse, String errorResponse, int? maxLengthFaultString){
_succesResponse = succesResponse;
_errorResponse = errorResponse;
_maxLengthFaultString = maxLengthFaultString;
}

public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters){
}

public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase){

CustomTechKundanBTSResponseProviderMessageInspector inspector = null;
foreach (ChannelDispatcher chDisp in serviceHostBase.ChannelDispatchers){

foreach (EndpointDispatcher epDisp in chDisp.Endpoints){
inspector =
new CustomTechKundanBTSResponseProviderMessageInspector(_succesResponse, _errorResponse, _maxLengthFaultString);epDisp.DispatchRuntime.MessageInspectors.Add(inspector);
}
}
}

public void Validate(ServiceDescription serviseDescription, ServiceHostBase serviceHostBase){
}
}
}


3. Compile and GAC the dll .
4. Add below line to 2.0 and 4.0 machine.config both at 32bit and 64bit machine.config files.
<add name="CustomTechKundanBTSResponse" type="Kundan.Integrations.WCF.CustomTechKundanBTSResponseProviderBehaviorExtensionElement, Kundan.Integrations.WCF.CustomTechKundanBTSResponse, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c1a801be9a87ef72" />

Re-start IIS and BizTalk Host instances.
5. Go to WCF-Custom (or WCF-CustomIsolated) receive location and on Behaviour tab ,
right click and Add-Extension
the you can able to see CustomTechKundanBTSResponse in the list, Add it and provide Success and Fault Response XMLs.




Now Test it eith by your application or by SOAPUI.





Friday, September 7, 2012

Generic DataBase connection code in C#.net

using System;
using System.Reflection;using System.Data;using System.Data.OleDb;using System.Data.SqlClient;using System.Data.OracleClient;namespace KundanCorner.ProviderFactory{

/// <summary>/// The collection of ADO.NET data providers that are supported by <see cref="ProviderFactory"/>./// </summary>public enum ProviderType{

/// <summary>/// The OLE DB (<see cref="System.Data.OleDb"/>) .NET data provider./// </summary>OleDb = 0,
/// <summary>/// The SQL Server (<see cref="System.Data.SqlClient"/>) .NET data provider./// </summary>SqlClient,
OracleClient
};
/// <summary>/// The <b>ProviderFactory</b> class abstracts ADO.NET relational data providers through creator methods which return/// the underlying <see cref="System.Data"/> interface./// </summary>/// <remarks>/// This code was inspired by "Design an Effective Data-Access Architecture" by Dan Fox (.netmagazine, vol. 2, no. 7)/// </remarks>public class ProviderFactory{#region private variables
private static Type[] _connectionTypes = new Type[] { typeof(OleDbConnection), typeof(SqlConnection), typeof(OracleConnection) };
private static Type[] _commandTypes = new Type[] { typeof(OleDbCommand), typeof(SqlCommand), typeof(OracleCommand) };
private static Type[] _dataAdapterTypes = new Type[] { typeof(OleDbDataAdapter), typeof(SqlDataAdapter), typeof(OracleDataAdapter) };
private static Type[] _dataParameterTypes = new Type[] { typeof(OleDbParameter), typeof(SqlParameter), typeof(OracleParameter) };
private ProviderType _provider;#endregion
#region
ctors
private ProviderFactory() { } // force user to specify providerpublic ProviderFactory(ProviderType provider){
_provider = provider;
}
#endregion
#region
Provider property
public ProviderType Provider{

get{
return _provider;}

set{
_provider =
value;}
}
#endregion#region IDbConnection methods
public IDbConnection CreateConnection(){

IDbConnection conn = null;
try{
conn = (
IDbConnection) Activator.CreateInstance(_connectionTypes[(int) _provider]);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}


return conn;}

public IDbConnection CreateConnection(string connectionString){

IDbConnection conn = null;
object[] args = {connectionString};
try{
conn = (
IDbConnection) Activator.CreateInstance(_connectionTypes[(int) _provider], args);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}


return conn;}
#endregion#region IDbCommand methods
public IDbCommand CreateCommand(){

IDbCommand cmd = null;
try{
cmd = (
IDbCommand) Activator.CreateInstance(_commandTypes[(int) _provider]);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}


return cmd;}

public IDbCommand CreateCommand(string cmdText){

IDbCommand cmd = null;
object[] args = {cmdText};
try{
cmd = (
IDbCommand) Activator.CreateInstance(_commandTypes[(int) _provider], args);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}


return cmd;}

public IDbCommand CreateCommand(string cmdText, IDbConnection connection){

IDbCommand cmd = null;
object[] args = {cmdText, connection};
try{
cmd = (
IDbCommand) Activator.CreateInstance(_commandTypes[(int) _provider], args);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}


return cmd;}

public IDbCommand CreateCommand(string cmdText, IDbConnection connection, IDbTransaction transaction){

IDbCommand cmd = null;
object[] args = {cmdText, connection, transaction};
try{
cmd = (
IDbCommand) Activator.CreateInstance(_commandTypes[(int) _provider], args);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}


return cmd;}
#endregion#region IDbDataAdapter methods
public IDbDataAdapter CreateDataAdapter(){

IDbDataAdapter da = null;
try{
da = (
IDbDataAdapter) Activator.CreateInstance(_dataAdapterTypes[(int) _provider]);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}

return da;}

public IDbDataAdapter CreateDataAdapter(IDbCommand selectCommand){

IDbDataAdapter da = null;
object[] args = {selectCommand};
try{
da = (
IDbDataAdapter) Activator.CreateInstance(_dataAdapterTypes[(int) _provider], args);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}

return da;}

public IDbDataAdapter CreateDataAdapter(string selectCommandText, IDbConnection selectConnection){

IDbDataAdapter da = null;
object[] args = {selectCommandText, selectConnection};
try{
da = (
IDbDataAdapter) Activator.CreateInstance(_dataAdapterTypes[(int) _provider], args);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}

return da;}

public IDbDataAdapter CreateDataAdapter(string selectCommandText, string selectConnectionString){

IDbDataAdapter da = null;
object[] args = {selectCommandText, selectConnectionString};
try{
da = (
IDbDataAdapter) Activator.CreateInstance(_dataAdapterTypes[(int) _provider], args);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}

return da;}
#endregion
#region
IDbDataParameter methods
public IDbDataParameter CreateDataParameter(){

IDbDataParameter param = null;
try{
param = (
IDbDataParameter) Activator.CreateInstance(_dataParameterTypes[(int) _provider]);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}

return param;}

public IDbDataParameter CreateDataParameter(string parameterName, object value){

IDbDataParameter param = null;
object[] args = {parameterName, value};
try{
param = (
IDbDataParameter) Activator.CreateInstance(_dataParameterTypes[(int) _provider], args);}

catch (TargetInvocationException e){

throw new SystemException(e.InnerException.Message, e.InnerException);}

return param;}

public IDbDataParameter CreateDataParameter(string parameterName, DbType dataType){

IDbDataParameter param = CreateDataParameter();
if (param != null){
param.ParameterName = parameterName;
param.DbType = dataType;
}


return param;}

public IDbDataParameter CreateDataParameter(string parameterName, DbType dataType, int size){

IDbDataParameter param = CreateDataParameter();
if (param != null){
param.ParameterName = parameterName;
param.DbType = dataType;
param.Size = size;
}


return param;}

public IDbDataParameter CreateDataParameter(string parameterName, DbType dataType, int size, string sourceColumn){

IDbDataParameter param = CreateDataParameter();
if (param != null){
param.ParameterName = parameterName;
param.DbType = dataType;
param.Size = size;
param.SourceColumn = sourceColumn;
}


return param;}
#endregion}
}