Complete BizTalk project to host Schema as Web Service Skip to main content

Complete BizTalk project to host Schema as Web Service

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);

Exp_GeneralException:
System.Diagnostics.EventLog.WriteEntry("WSSchema: ","Receive General Exception");
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);

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 !!

Comments

  1. This server is very usefull for students ,thanks for good info BizTalk Online Training

    ReplyDelete
  2. Hey, How you have created or configuredRequest, response and Fault_Error on AccReqRes of WSGetReqRes Recive port?

    ReplyDelete
    Replies
    1. With the help of BizTalk WCF Service Publish Wizard or you can also manually create Receive port and receive location for it.

      Delete
  3. titanium astroneer - The Tithron® - TITIAN® - The Tithron®
    Titanium 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

    ReplyDelete

Post a Comment

Please write comment only that belongs to this blog

Popular posts from this blog

BizTalk Interview Question and Answer

1. What is BizTalk? BizTalk is a middleware that sits in the middle of any two software who wish to communicate with each other and agree on some specified communication pattern. It uses SQL Server as back end database. “Microsoft BizTalk Server is an Inter-Organizational Middleware System (IOMS) that enables companies to automate business processes, through the use of adapters which are tailored to communicate with different software systems used in an enterprise. Created by Microsoft, it provides enterprise application integration, business process automation, business-to-business communication, message broker and business activity monitoring.”                 2. What is BizTalk Server Architecture and Life Cycle of Message? BizTalk Server Architecture: Life Cycle of Message: In this simplified view, a message is received through a receive location defined in a given receive port. This message is processed by the receive locatio

Configuring BizTalk WCF Timeout Values on a Binding

There are a number of timeout settings available in WCF bindings. Setting these timeout settings correctly can improve not only your service’s performance but also play a role in the usability and security of your service. The following timeouts are available on WCF bindings: OpenTimeout CloseTimeout SendTimeout ReceiveTimeout Open Timeout :  This property represents the amount of time a channel open operation has to complete. Send Timeout :  Use this property to set the amount of time that a send operation has to complete. When used as part of a solicit-response scenario, this value encompasses the total amount of time for the interaction to complete. If we are sending a large message, we may need to increase this timeout to allow for the request and response messages to be processed within this window. Close Timeout :  A time-stamp that is used to indicate the amount Receive Timeout :  Used by the Service Framework Layer to initialize the session-idle timeo

PowerShell Script to enable BizTalk Receive Location

We are facing problem in BizTalk server 2016 that few of running SFTP Receive location would be stopped after some time due to sftp connectivity issue of their threshold so I am going to share PowerShell script to enable receive location by window task scheduler. Before execute following script Please do following task a. Set Server name in ConnectionString b. Set ( $hostname) host name value that is using in SFTP Receive location c. Set ( $rcvLocation) Receive location name # Import external assembly and create a new object [ void ] [ System.reflection.Assembly ]:: LoadWithPartialName( "Microsoft.BizTalk.ExplorerOM" ) $Catalog = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer   #BizTalk Config $Catalog . ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI"   #connectionstring for the BizTalkMgmtDb $hostname = "BizTalkServerApplication" #hostname $rcvLocation = "RL_GetAccReq_SQL

Step by step solution of BizTalk Two-Way WCF-SQL XmlPolling in Send Port

I am going to share most awaited Two way WCF_SQL Two Way XmlPolling so that you can easily enhance your old SQL procedure and BizTalk Map without any big change. I know there is no content available in any website to how work with XmlPolling in WCF-SQL two-way adapter. In the last of this post you can download complete source code with an example. Please follow carefully all steps – 1. Open Microsoft Visual Studio as Administrator user and Click File>New>Project… In Installed Templates click BizTalk Projects then Empty BizTalk Server Project and Name as “BizTalkLive-WCF-SQL” and click OK. 2. Now see the below picture and create all respective folders separately for Schema, Map, Orchestration, Pipeline, Binding- 3. Create Schemas in Schema folder as shown below picture to get Account request using One Way WCF-SQL XmlPolling a) Create Envelope Schema first with Target NameSpace - http://BizTalkLive_WCF_SQL.AccountRequest b) Create Second Sch

Publish a web service in biztalk using BizTalk WCF Service Publishing Wizard

Welcome you again in my Blog and let us do another mind blowing achievement that how to publish a WCF web service in BizTalk and as in previous post to Complete BizTalk project to host Schema as Web Service  so If you want to expose/publish a web service, you should run through the BizTalk WCF Service Publishing Wizard. This wizard guides you through choosing what you want to expose as a web service. This section walks you through the wizard step by step to publish WCF Web Service using  WCF-WSHttp- Step-1:  To start the wizard, go to Start, All Programs, Microsoft BizTalk Server 2016(version), BizTalk WCF Service Publishing Wizard. This fires up a welcoming screen, on which you just click Next. Consider disabling the welcoming screen for the future by checking the check box at the bottom. You will now see the screen shown in above figure. Step-2: Choose the Service Endpoint option, and choose which adapter to use. Check Enable Metadata Endpoint if you want to expose t