Biztalk Development calls the Web Services

Source: Internet
Author: User
Tags empty web services xmlns biztalk

There are several forms of interaction between Biztalk Server 2004 and Web services:

1. Call the Web Services in BizTalk Server;
2. Publish the BizTalk Server schema as a Web Services;
3. Publish the business process for BizTalk Server as a Web services;

In the context of the release of the BizTalk Development Architecture, we discussed the second form. In this article, you specifically describe how to call Web Services in BizTalk Server.

Calling Web Services in BizTalk Server, typical applications include four types of messages:

A. Import message-a message received from an external application received from the receive pipeline to BizTalk Server;
B. Request message-A message requested from BizTalk Server to Web services;
C. Response messages-messages returned from Web services to BizTalk Server;
D. Output messages-messages from BizTalk Server output to external apps.

In BizTalk Server, each message has its own message type. The message types of messages B and C, which are generated automatically by BizTalk Server. Specifically, it is generated when a Web services is added to a Web reference for a BizTalk Server project, and messages A and d are determined by the content of the messages that are imported and exported.

In a specific application, the import message may be the same structure as the output message, except that some fields of the import message are empty, and by invoking Web services, the fields are fully replenished and then exported outward. Typically, calling Web services in BizTalk Server requires completing the following tasks:

First, create a web Service
Second, create a BizTalk Server project and add a Web reference
Third, create a schema that defines the type of import and output message
Iv. Creating business Processes
V. Compiling, deployment and testing

Here's a look at the steps:

First, create a web Service

1. Under C:/inetpub/wwwroot, create a testservice.asmx file with the following source program:

<%@ WebService language= "C #" class= "Testservice"%>

Using System;

Using System.Collections;

Using System.ComponentModel;

Using System.Data;

Using System.Diagnostics;

Using System.Web;

Using System.Web.Services;

public class TestService:System.Web.Services.WebService

{

[WebMethod]

public string Checkuserid (string strUserID)

{

if (strUserID = = "Fengfangfang")

{

return "Administrator";

}

Else

{

return "User";

}

}

}

2. In the browser, enter Http://localhost/TestService.asmx to test the Web service.

Second, create a BizTalk Server project

3. Open Visual Studio. Net 2003, create a new project, select the project type for the BizTalk project, the template is empty for the BizTalk Server Project, and enter the name WebServices1.

4. Add a Web References to the WEBSERVICES1 project in Solution Explorer with a URL of http://localhost/TestService.asmx.

Third, create a schema that defines the type of import and output message

5. Add a new item for the WEBSERVICES1 project, select the schema, and enter the name Userinfo.xsd.

6. Rename the root to UserInfo and add two child field elements, with the names UserID and RoleName, respectively.

7. Select the UserID element, right-click to select Upgrade/Quick upgrade, and upgrade the rolename in the same way.
Note: Since you are using UserID as a parameter to pass to the Web service, you will need to update the rolename after the Web service returns the message, so the two elements need to be upgraded so that their values can be accessed and set in the orchestration.

Iv. Creating business Processes

8. Add a new item for the WEBSERVICES1 project, select the BizTalk Orchestration, and set the name to Orchestration1.odx.

9. Create a Requestwebservice message in the Orchestration view with a message type of Web message type/webservices1.localhost.testservice_. Checkuserid_request; Creates a responsewebservice message with a message type of/webservices1.localhost.testservice_ for the web message type. Checkuserid_response; Create inmsg and OUTMSG messages with a message type of schema/webservices1.userinfo.

10. Create a port, set the port name to Wsport, use the existing port type, and select Web Port type/webservices1.localhost.testservice_. Testservice, the rest selects the default value to complete the wizard.

11. Add a receive Operation receiveinmsg for the orchestration to receive messages from the external application, and then add a message assignment operation Assignrequest, named Constructrequest, for the automatically added construction message. Used to construct requestwebservice messages; Add a send message call WS and one receive message receive WS operation, which is used to contact Wsport to implement calls to the Web service; Add a message assignment operation. The construct message named Auto-added is constructoutmsg, which is used to generate outmsg; a send operation Sendoutmsg is added to send the OUTMSG message.

12. Set the message for call WS to Requestwebservice and connect to the Wsport request port, and set the message for receive WS to Responsewebservice, and connected to the response port of the Wsport.

13. Set the message for Receiveinmsg to Inmsg, and set the SENDOUTMSG message to outmsg.

14. Set the Constructrequest construct message to Requestwebservice, set the CONSTRUCTOUTMSG construct message to outmsg.

15. Enter the following expression for Assignrequest:
Requestwebservice.struserid = Inmsg (WebServices1.PropertySchema.UserId);
Description: This statement represents the strUserID element that assigns a userid to Requestwebservice.

16. Enter the following expression for assignoutmsg:
outmsg=inmsg;
Outmsg (WebServices1.PropertySchema.RoleName) = Responsewebservice.checkuseridresult;
Note: The first sentence assigns the input message directly to the output message, the second sentence updates the rolename element of the output message, replacing its value with the return value of the Web service.

17. Place a port on the port surface, set the name to ReceivePort according to the Port Configuration Wizard, the port type name is Receiveporttype, the port traffic direction is always receive the message on this port, the port is specified as immediate; Set the transfer to file, set the URI to C :/in/*.xml, set the receive pipeline to Microsoft.BizTalk.DefaultPipelines.XMLReceive.

18. Place a port on the port surface, set the name SendPort, set the port type to Sendporttype, set the port communication direction to always send a message on this port, set the port binding to specify now, set the transfer to file, set the URI to c:/out/% Messageid%.xml, set the Send pipeline to Microsoft.BizTalk.DefaultPipelines.XMLTransmit.

19. Connect the Receive Port ReceivePort with the receiveinmsg operation and connect the SendPort to the sendoutmsg.

20. Set the activation property of the receiveinmsg operation to True.

V. Compiling, deployment and testing

21. Select Build/Build solution to compile the project.

22. Select the Build/Configuration Manager menu and select the Deploy check box.

23. Select the Project/webservices1 Properties menu to set common Properties, assemblies/assembly key files for the project. The creation of the key file is described in the article requiring a strong name assembly.

24. Select the build/deploy solution to deploy the project.

25. Refresh the BizTalk Configuration database in BizTalk Explorer, and the Webservices1.orchestration1 node will appear under the orchestration to start the business process.

26. Placing the test file in the C:/in folder will automatically output the XML file in the C:/out folder.

Put the contents of the test file Test.xml:

<ns0:userinfo xmlns:ns0= "Http://WebServices1.UserInfo" >

<UserId>fengfangfang</UserId>

<RoleName></RoleName>

</ns0:UserInfo>

The contents of the output file:

<?xml version= "1.0" encoding= "Utf-8"? ><ns0:userinfo xmlns:ns0= "Http://WebServices1.UserInfo" >

<UserId>fengfangfang</UserId>

<RoleName>Administrator</RoleName>

</ns0:UserInfo>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.