Hello BizTalk Developer ! Today I am come to here for a very useful and much awaited project that how create solution - schema as web service in BizTalk. It is very useful those who are beginner or a expertise in BizTalk. There are two way in biztalk to host a web service either schema as web service or orchestration as web service but better way to host web service using schema because orchestration as service will be strongly coupled. In my next post i will be host orchestration as web service.
So please follows all following steps to create a biztalk solution i.e. host schema as web service-
Step-1: Open Visual studio as administrator and from file menu select >New>>Project then click on BizTalk Projects tab from left side and select Empty BizTalk Server Project from the middle then in below side in name set project name as "BizTalkLive.WS.Schema" and same solution name too after that click OK button.
Step-2: Right click on your project in VS then add two folder (one by one) i.e. Orchestration and Schema. Now right click on schema folder and add three schema one is for web service request, second for web service response and last one for handle custom fault error and if error occurs then get it to back to client server.
Web Service Request schema name is : "AccountRequest.xsd" and schema structure are-
<?xml
version="1.0" encoding="utf-16" ?><xs:schema xmlns="http://BizTalkLive_WebService_Schema.AccountRequest" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" elementFormDefault="qualified" targetNamespace="http://BizTalkLive_WebService_Schema.AccountRequest" xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="AccountsRequest"> <xs:complexType><xs:sequence> <xs:element name="AccountNumber" type="xs:string" /> <xs:element name="IFSCCode" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Web Service Response schema name is : "AccountResponse.xsd" and also promote all element as visible in following picture so we can easily assign value for it , see the schema structure are-
<?xml
version="1.0" encoding="utf-16" ?>
<xs:schema xmlns="http://BizTalkLive_WebService_Schema.AccountResponse" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" elementFormDefault="qualified" targetNamespace="http://BizTalkLive_WebService_Schema.AccountResponse" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="AccountsResponse"><xs:annotation><xs:appinfo>
<b:properties xmlns:b="http://schemas.microsoft.com/BizTalk/2003">
<b:property distinguished="true" xpath="/*[local-name()='AccountsResponse'
and
namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']/*[local-name()='AccountNumber'
and namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']" />
<b:property distinguished="true" xpath="/*[local-name()='AccountsResponse'
and
namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']/*[local-name()='AccountFirstName'
and namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']" />
<b:property distinguished="true" xpath="/*[local-name()='AccountsResponse'
and
namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']/*[local-name()='IFSCCode'
and namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']" />
<b:property distinguished="true" xpath="/*[local-name()='AccountsResponse'
and
namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']/*[local-name()='AccountType'
and namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']" />
<b:property distinguished="true" xpath="/*[local-name()='AccountsResponse'
and
namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']/*[local-name()='AccountStatus'
and namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']" />
<b:property distinguished="true" xpath="/*[local-name()='AccountsResponse'
and namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']/*[local-name()='AccountValidity'
and namespace-uri()='http://BizTalkLive_WebService_Schema.AccountResponse']" />
</b:properties></xs:appinfo></xs:annotation><xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="AccountNumber" type="xs:string" /><xs:element name="AccountFirstName" type="xs:string"
/>
<xs:element name="IFSCCode" type="xs:string" /><xs:element name="AccountType" type="xs:string" />
<xs:element name="AccountStatus" type="xs:string" /><xs:element name="AccountValidity" type="xs:string" />
</xs:sequence></xs:complexType></xs:element></xs:schema>
Web Service Custom fault schema name is : "Error.xsd" then promote both elements and schema structure are-
<?xml
version="1.0" encoding="utf-16" ?>
<xs:schema xmlns="http://BizTalkLive_WebService_Schema.Schema.Error" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" elementFormDefault="qualified" targetNamespace="http://BizTalkLive_WebService_Schema.Schema.Error" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Errors"><xs:annotation><xs:appinfo>
<b:properties xmlns:b="http://schemas.microsoft.com/BizTalk/2003">
<b:property distinguished="true" xpath="/*[local-name()='Errors'
and namespace-uri()='http://BizTalkLive_WebService_Schema.Schema.Error']/*[local-name()='ErrorCode'
and namespace-uri()='http://BizTalkLive_WebService_Schema.Schema.Error']" />
<b:property distinguished="true" xpath="/*[local-name()='Errors'
and namespace-uri()='http://BizTalkLive_WebService_Schema.Schema.Error']/*[local-name()='ErrorDesc'
and namespace-uri()='http://BizTalkLive_WebService_Schema.Schema.Error']" />
</b:properties></xs:appinfo></xs:annotation><xs:complexType><xs:sequence>
<xs:element name="ErrorCode" type="xs:string" /><xs:element name="ErrorDesc" type="xs:string" />
</xs:sequence></xs:complexType></xs:element></xs:schema>
Step-3: Now right click on Orchestration folder from your project and create orchestration name as "orchWSSchema.odx". See the following image-
In showing in above picture, firstly I am create a new request-response port and also add a fault message that get back to destination system if any error occur during process. You can add multiple fault message in same request-response port as per your requirement. In right side you can see variable too later I will discuss on it. Now create new message and assign schema name respectively as showing right side in orchestration view.
See the following value of expression shape i.e. Exp_SetAccountRes, Exp_SystemException and Exp_GeneralException respectively-
Exp_SetAccountRes:
System.Diagnostics.EventLog.WriteEntry("Account: ","Account response has assigned",System.Diagnostics.EventLogEntryType.Information,1);
varSuccess=true;
varAccountFirstName="Jitendra";
varAccountStatus="A";
varAccountType="SB";
varAccountValidity="V";
//varNumber =1/System.Convert.ToInt32(varAccountStatus); //Rremove "//" string to get system exception
Exp_SystemException:
varSuccess=false;
varErrorCode = "101";
varErrorDesc = objSystemException.Message.ToString();
System.Diagnostics.EventLog.WriteEntry("WSSchema: ","Receive System error : "+varErrorDesc+"-"+varErrorCode);
varErrorCode = "101";
varErrorDesc = objSystemException.Message.ToString();
System.Diagnostics.EventLog.WriteEntry("WSSchema: ","Receive System error : "+varErrorDesc+"-"+varErrorCode);
Exp_GeneralException:
System.Diagnostics.EventLog.WriteEntry("WSSchema: ","Receive General Exception");
varSuccess=false;
varErrorCode = "103";
varErrorDesc = "Received General Error";
varSuccess=false;
varErrorCode = "103";
varErrorDesc = "Received General Error";
Step-4: As we know in web service when we request a web service either we receive web service response or web service fault message so I have added here decide shape and response accordingly. In rule shape set Boolean value of variable varSuccess == false see the following image-
As showing in picture I have construct message for fault message in left side of decide shape and similar constructed message for right side of decide shape and message assignment value are-
Message Assignment Shape for Fault Message-
varSaopXml = new System.Xml.XmlDocument();
varSaopXml.LoadXml("<ns0:Errors xmlns:ns0='http://BizTalkLive_WebService_Schema.Schema.Error'>"+
"<ns0:ErrorCode>ErrorCode_0</ns0:ErrorCode>"+
"<ns0:ErrorDesc>ErrorDesc_0</ns0:ErrorDesc>"+
"</ns0:Errors>");
msgSoapFault = varSaopXml;
msgSoapFault.ErrorCode = varErrorCode.ToString();
msgSoapFault.ErrorDesc = varErrorDesc.ToString();
System.Diagnostics.EventLog.WriteEntry("WSSchema: ","Send Soap Exception "+varErrorDesc);
varSaopXml = new System.Xml.XmlDocument();
varSaopXml.LoadXml("<ns0:Errors xmlns:ns0='http://BizTalkLive_WebService_Schema.Schema.Error'>"+
"<ns0:ErrorCode>ErrorCode_0</ns0:ErrorCode>"+
"<ns0:ErrorDesc>ErrorDesc_0</ns0:ErrorDesc>"+
"</ns0:Errors>");
msgSoapFault = varSaopXml;
msgSoapFault.ErrorCode = varErrorCode.ToString();
msgSoapFault.ErrorDesc = varErrorDesc.ToString();
System.Diagnostics.EventLog.WriteEntry("WSSchema: ","Send Soap Exception "+varErrorDesc);
Message Assignment Shape for Response Message-
System.Diagnostics.EventLog.WriteEntry("WSSchema: ","Account res has started for construction");
varGetXML = new System.Xml.XmlDocument();
varGetXML.LoadXml("<ns0:AccountsResponse xmlns:ns0='http://BizTalkLive_WebService_Schema.AccountResponse'>"+
"<ns0:AccountNumber>AccountNumber_0</ns0:AccountNumber>"+
"<ns0:AccountFirstName>AccountFirstName_0</ns0:AccountFirstName>"+
"<ns0:IFSCCode>IFSCCode_0</ns0:IFSCCode>"+
"<ns0:AccountType>AccountType_0</ns0:AccountType>"+
"<ns0:AccountStatus>AccountStatus_0</ns0:AccountStatus>"+
"<ns0:AccountValidity>AccountValidity_0</ns0:AccountValidity>"+
"</ns0:AccountsResponse>");
System.Diagnostics.EventLog.WriteEntry("WSSchema: ","Account res has initiated to assign account response");
msgSendAccRes =varGetXML;
msgSendAccRes.AccountFirstName=varAccountFirstName.ToString();
msgSendAccRes.AccountNumber=xpath(msgGetAccReq,"string(/*[local-name()='AccountsRequest' and namespace-uri()='http://BizTalkLive_WebService_Schema.AccountRequest']/*[local-name()='AccountNumber' and namespace-uri()='http://BizTalkLive_WebService_Schema.AccountRequest'])");
Step-5: Now right click on biztalk project from visual studio and select properties then from right side tab list select Signing then create new strong name key as "snBizTalkLiveWSSchema.snk". Now go to Deployment tab and set Application Name as "BizTalkLive.WS.Schema". Again right click on project and build it then finally deploy it.
In above all steps I have done how we create schema as web service project in biztalk and see the following link how we publish web service in BizTalk using Publishing Wizard : publish web service
!! Keep visiting BizTalkLive !!
This server is very usefull for students ,thanks for good info BizTalk Online Training
ReplyDeleteThanks Swathi !
ReplyDeleteHey, How you have created or configuredRequest, response and Fault_Error on AccReqRes of WSGetReqRes Recive port?
ReplyDeleteWith the help of BizTalk WCF Service Publish Wizard or you can also manually create Receive port and receive location for it.
Deletetitanium astroneer - The Tithron® - TITIAN® - The Tithron®
ReplyDeleteTitanium is a stainless steel stainless steel solid 포커 족보 core that is made with stainless steel making a titanium vs platinum reliable addition to your game. It has an trekz titanium headphones aluminium Rating: 4.2 · titanium wood stove 8 used ford escape titanium reviews · £2.85 · In stock