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.