Total Pageviews

Sunday, July 10, 2016

How to generate Xml Schema to consume WCF service

How to generate Xml Schema to consume WCF service

There are 3 ways you can generate the schema against the WCF service.
1)      Using BizTalk WCF Service Consume Wizard, by adding Metadata Exchange Point.
2)      Using BizTalk WCF Service Consume Wizard, by adding Metadata file (WSDL) Point.
3)      By Adding service reference

We will go one by one, before start, one should have the WCF service endpoint provided by partner and it should be accessible from development environment or from where you are developing the BizTalk solution. If you don’t have access to service then at least you should have .wsdl file of the service, so using option 2, you can generate the schema.

Let’s say we have to consume a wcf service and all necessary access is there in place. Now in order to consume the wcf service, the very first step is to generate the necessary schema in Biztalk. Let’s say below is service url and it is accessible from the dev environment.
s

Make sure it is accessible from you dev. Browse it in explorer or chrome and below screen should appear.




(I created this service for example purpose and it is in my local box, that’s why you are seeing localhost there…otherwise it would be some valid domain name) We will use this url for generating schema by above mentioned 3 ways. Let’s discuss one by one.


a)      Using BizTalk WCF Service Consume Wizard, by adding Metadata Exchange Point.

Follow below steps to generate schema using this option.
1)      Create a new folder in your project (optional, it give better understanding what are all the items get generated when we consume the service , as we see all items in separate folder. ) right click Folderà add new folderà give some good name.




2)      Right click projectà AddàAdd Generated itemsà select consume wcf service from left sideàAdd.



3)      BizTalk WCF Service Conusming Wizard will open , click next


4)      Select Meta Data Exchange (MEX) endpoint and click  Next.


5)      Enter the service url in Metadata Address (URL) and click  on Get, once service gets loaded click Next.



6)      Provide the namespace and click on Import. In next screen click finish.



7)      Open the folder where the items are added.



8)      5 items are added  in the folder.

                                                        i.            HelloService_pragimtech_com_ServiceVersion1:
            This the actual schema that is generated. Double click on it and you can see the methods of service. It created two nodes for each method one is for request and another is for response. This is based on the operation that service is providing.





                                                      ii.            HelloService_schemas_microsoft_com_2003_10_Serialization:
            This is used for serialization double click and you can see the different data types there.
                                                    iii.            Two Binding files:
This are used to create the send port in BizTalk admin console. We need to import any one of the binding file in admin console so that send port corresponding to this service is being created.
If you are consuming wcf service first time then import the binding from here, later we can create send port manually as well.

                                                     iv.            One empty orchestration:

If you open the orchestration you will not see anything. At first look it seems that this orchestration is of no use. But if we explore it will find some useful information. Double click the orchestration and click orchestration view, explore the Port Types and Multi-part Message types. You will see that a new port and two messages are created in this orchestration.





                                                            Importance of this is ,generally in a BizTalk solution Schema, Maps, Orchestrations are created in separate projects. So when the reference of schema project is added to orchestration project, ports and message types are ready to use there and no need to create new ports and message type in orchestration. Only thing you need to do is to make the port and message type public in schema project before build. To do so right click on the port or message type and click properties. There in type modifier change internal to public.

            That’s it now you have the schema ready to consume the WCF service.



b)      Using BizTalk WCF Service Consume Wizard, by adding Metadata file (WSDL) Point.

To use this option we should have the WSDL file available with use, if it is not there and you are able to access the service, you can get it.
Browse the service and click on the second link , a wsdl file  will open save it in some folder as .wsdl.





WSDL file  looks like below:





1)      Follow 1 to 3 step as discussed in first option.
2)      Select Meta Data files from the option and click next.




Add WSDL file and click on next and then import.  You will find the same items are generated in the folder, which were generated using option 1.







c)      By Adding service reference

To use this option also, we should have access to service. Follow below steps to generate schema using this option.

1)      Right Click on the Reference folder of the project à Add Service reference.



2)      Provide the address of the service and click on Go. Once service is loaded click Ok.


3)      You will not see any of schema generated in the solution explored, only thing you will see is that one folder with name Service Reference is created and one service with name space ServiceReference1 is added there. So where is the schema??


4)      To see the schema , right click on the project and click on ‘Open folder in file explorer’ and navigate to Service References\ServiceReference1


5)      You will see 2 wsdl and 2 xsd file is generated there and some other files also generated... Add the 4 files as existing item in folder of schema project.
6)      This are same schema as generate earlier. Using this option we will not get the binding files and empty orchestration automatically created.
7)      You can rename the Schema file and lastly the added service reference can be deleted as well, because it is of no use from Biztalk Point of view.



This covers, the way of generating the schema to consume the wcf service. Hope you will like it and provide your feedback and suggestions.


Friday, July 8, 2016

How to Generate Xml Schema from JSON message

Now a day’s most of the partners are using JSON message for the communication because it is light weight and requires less memory. Since BizTalk Server 2013 R2, it became very easy to generate xml schema against the JSON message. Follow below steps to do so.

1)      Let us say partner provide below JSON message format and you have to consume it in BizTalk.  Copy below in notepad file and save it as .json file.

{
    "Name": {
      "Fname": "Fname_0",
      "Lname": "Lname_0"
    },
    "Address": {
      "Street": "Street_0",
      "City": "City_1",
      "Address": "Address_2"
    }
}

2)      Right click on project->Add New Itemàselect JSON Schema Wizard and give name of the schema and click Add.



3)       In Instance file, browse the location of json file you saved in step 1. Provide the root node name and target namespace as you want. Click on finish.




4)      You will find the document schema generated in the project. 

Saturday, July 2, 2016

How to Generate Xml Schema in BizTalk

How to Generate Xml Schema

There are three ways to generate the Xml Schema in BizTalk.

1)      Using Existing XSD:

If suppose partner provides the XSD from his end then we can simply add that schema in our project using add existing item.
 This method is generally not used, because it is not necessary that either or both receiving and sending partner knows about the XSD and they have it ready made.

            Follow below steps to add any existing item in project.




2)      Using Xml file

This is the most commonly used format that partner provides and can be used to generate the xml Schema in BizTalk. Any of the partner (Receiver or Sender) provides the xml file based on their requirement then it can be used handy to generate the xml schema. Follow below steps to Generate the Xml Schema from xml file.

a)      Right Click project-> Add->AddGenerateditems


b)      Click on Generated Schema and then click Add.


                                                   
c)      Click on Well-formed Xml rom drop down list, select the xml file provided by partner and then click ok. You can see a schema corresponding to your xml is generated.



Some time you will not get this option in drop down list. Especially when you install  BizTalk. first time.
Do following in this case.
·         Go to below directory and copy the two .dll files.
                        
(One is for DTD to Xsd generator and another is for Wellform Xml to Xsd generator.)


            C:\(Program files (X86) or Program files )\Microsoft Biztalk Server 2010/2013/2013 R2\SDK\Utilities\Schema Generator\:


·         Paste in below location.

C:\ (Program files (X86) or Program files)\Microsoft BizTalk Server 2010/2013/2013 R2\Developer Tools\Schema Editor Extensions

·         Close the visual studio and open again and then try to add existing schema, you will find this option there.


d)      Observe the property of the schema. Target namespace is one of the important properties of the schema and it should be set correctly. Sometimes it auto generated based on the xml message provided by partner. However we can change it based on the customer requirements and their standards. Generally it looks something like http://businesssolution.schemaname/schemaspecification/Version 1.0.0.0 .   It is important property because it contributes in calculating the message type which uniquely identifies the schema across all application of the BizTalk.



3)      Manual Generate the Xml Schema

We can generate the xml schema manually as well. For this purpose you should have all fields , attributes and Record information from the partner, what will be the data type  and their length , all such information should be with you according to agreed requirement between developer and the partner. To generate the Xml Schema manually follow below steps.

Let us say you have below xml message received from partner and we have to create schema manually for this.




a)      Right Click project-> Add->New Item and select Schema, give suitable name for your schema and click Add.



b)      Rename the Root node to EmployeeRoot.
c)      Right Click  EmployeeRootàInsert Schema nodeà child Record. Give it name as Name.


d)      Fname and Lname are the fields as they are nested under Name node. So add 2 Child Field elements. Right click Nameà insert Schema Nodeà Child Field element.  Give them names as Fname and Lname
e)      Right Click Nameà Insert Schema Nodeà Sibling Record. Name it as Address.


f)       Now we can see in input message provide by partner , street, city and state as coming like attribute so we need to add attribute element on Address node.

Right click Addressà Insert Schema nodeà child Field Attribute.
Add 3 such nodes and give them name as Street, City and State.




g)      Save the schema finally it looks like below and you can click on any node and in properties you can change the data type length etc as per requirement.



Hope you like this article, provide your feedback and suggestion in comments. 


Sunday, June 26, 2016

What is canonical Schema?Why Canonical Schema required?

CANONICAL SCHEMA

What is canonical Schema?
Sometime situation comes where a developer need to create an internal schema to provide lose coupling, to increase performance factor.  Such internal schema which is created at BizTalk level (e.g. none of the receiver or sender uses this schema, it is for purely internal purpose of BizTalk) is called canonical schema.

Why Canonical Schema required?
In order to provide lose coupling between different orchestrations, to increase performance, to get less rework if input schema format changes, Canonical Schema is required.

Let us say we are receiving purchase order from a trading partner and this purchase order (input message) has to be sent to 3 different partners after applying some business logic in transforms (map). So we have to create 3 maps one for each partners. In this case source and destination system is tightly coupled. At later point of time suppose some fields in input message gets changed, so we need to change all 3 maps which leads more rework.

Now if we create an internal schema (canonical schema) and map the input message to this canonical schema. This canonical schema can be published to message box and from there other artifacts can subscribe it. There we can create maps from 3 different partners. Doing so we achieved the lose coupling.e.g. Source and destination systems are not tightly coupled. At later point of time if suppose some fields in input message is changed then we need to do changes in only one map. I.e. from input message to canonical which leads less rework. Having less rework and lose coupling the performance is also gets increased. Thus canonical schemas are helpful and if possible we should try to develop the solution creating the canonical schema.


Saturday, June 25, 2016

What are the different types of BizTalk Schema

SCHEMA IN BIZTALK

What is BizTalk Schema?

BizTalk is an integration technology and it basically connects different partner. Now different partner can send the message in different format. E.g. one partner can send the message in JSON format and receiver can accept the flat file. However BizTalk understand only xml format and if partners are using another format than first it needs to be converted to xml format. 
                In order to understand the xml format by BizTalk, we need to define the structure of the xml message. E.g. what will be the root node name, what will be the elements name, its data type, attributes name , structure of the message (which element will fall under which node) etc.  Schema does this work for BizTalk. Schema defines the structure of the messages which are being received in BizTalk and sent to partner. BizTalk uses XML Schema Definitions (XSDs) to describe the xml message. There are 4 types of schema in BizTalk.

1)      XML Schema
2)      Flat file Schema
3)      Envelope Schema
4)      Property Schema

XML Schema:
 If BizTalk has to receive an xml message then the schema which defines the structure of this xml message is called as xml schema.

e.g. below is the xml messages





Corresponding xml schema in BizTalk looks like this.



We can see here the schema is defining the xml messages, name of the elements their data types.

There are several properties of the schema which needs to be set like targetnamespace etc.

Flat file Schema: 
If BizTalk has to receive or send flat files then schema generated to define the structure of the flat file is called Flat file schema.

e.g below is the  flat file which contains only first name and last name of student which is comma separated.



Corresponding Flat File Schema generated in BizTalk looks like this.



Annotation tag is being added in schema to define the flat file schema. Legacy system uses the flat file schema and now a day’s most of the system uses either xml or JSON or EDI format for business. The flat file specification should be thoroughly agreed between businesses partners before developing the schema, small change in flat file can lead to large rework from development prospective.

Envelope Schema:
If partner wants to send more than one message having same structure in one shot e.g. partner wants to send the multiple student details in one message then we call that message as Envelope. In BizTalk we can de batch the Envelope message and send one message at a time to BizTalk.This can be achieved by envelop schema.  In order to create the envelope schema we need to set some schema property. Envelope property needs to be set to true and in Body xpath expression, need to provide body path of the document which is repeating structure. Both Flat file and Xml Schema can be treated as envelop schema and we can set property once double click on the schema and see property.




Generally the repeating node is Record.


Property Schema:
To understand the property schema, first we should know what property promotion is. Suppose we are receiving and xml message having student percentage and based on percentage we want to route the message to different department. In such cases we can promote the age from the message. The Age coming from xml instance messages is coming as content of the message. In order to route the message based on age, this property should be present in context of the message. Moving the content of message to context is called the property promotion and when we do so the promoted element is added to one Schema which takes care to move the values from content to context. This schema is called property schema.







Apart from these Schemas there is one more type of schema which is called as EDI Schema. Actually it is same as Flat File Schema , but considering the complexity of the EDI messages ,BizTalk provides around 8000+ EDI schemas and we can use them instead of generating on own.


To Read about Canonical Schema click here.