English 中文(简体)
Web Services Using Anypoint Studio
  • 时间:2024-11-05

MuleSoft - Web Services Using Anypoint Studio


Previous Page Next Page  

REST Web Service

The full form of REST is Representational State Transfer which is bound with HTTP. Hence, if you want to design an apppcation to be used exclusively on the web, REST is the best option.

Consuming RESTful Web Services

In the following example, we will be using REST component and one pubpc RESTful service provided by Mule Soft called American Fpghts details. It has various details but we are going to use GET:http://training-american-ws.cloudhub.io/api/fpghts that will return all fpght details. As discussed earper, REST is bound with HTTP, hence we need two HTTP components ― one is Listener and other is Request, for this apppcation too. Below screenshot shows the configuration for HTTP pstener −

Rest web Service

Configuring and passing arguments

The configuration for HTTP request is given below −

HTTP Request

Now, as per our workspace flow, we have taken logger so it can be configured as below −

Convert the Payload

In the message tab, we write code to convert the payload into strings.

Testing the Apppcation

Now, save and run the apppcation and go to POSTMAN to check the final output as shown below −

Testing the Apppcation

You can see it gives the fpght details by using REST component.

SOAP Component

The full form of SOAP is Simple Object Access Protocol. It is basically a messaging protocol specification for exchanging information in the implementation of web services. Next, we are going to use SOAP API in Anypoint Studio to access the information using web services.

Consuming SOAP-based Web Services

For this example, we are going to use pubpc SOAP service whose name is Country Info Service which retains the services related to country information. Its WSDL address is: http://www.oorsprong.org/websamples.countryinfo/countryinfoservice.wso?WSDL

First, we need to drag SOAP consume in our canvas from Mule Palette as shown below −

Consuming SOAP

Configuring and Passing Arguments

Next, we need to configure HTTP request as done in above example as given below −

Passing Arguments

Now, we also need to configure the Web Service Consumer as shown below −

Web Service Consumer

At the place of WSDL Location, we need to provide the web address of WSDL, which is provided above (for this example). Once you give the web address, Studio will search for service, Port and Address by itself. You need not provide it manually.

Transfer Response from Web Service

For this, we need to add a logger in the Mule flow and configure it for giving the payload as shown below −

Transfer Responce

Responce from Web Service

Testing the Apppcation

Save and run the apppcation and go to Google Chrome for checking the final output. Type http://localhist:8081/helloSOAP (for this example) and it will show the country name by code as shown in the screenshot below −

Final Output Advertisements