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.