Sei sulla pagina 1di 15

RFC-to-Web Service Scenario

by Neeraja This document describes how the Custom RFC client application in SAP R/3 System invokes a free Web service (that is hosted over the internet) using SAP XI. For our demo purpose, we have used a free web service available on the Internet. Details for the same are provided in the next section. About the web service: In this example scenario we will be using GetQuote method of Web service DelayedStockQuote. This method retrieves the Stock quote for the given Stock symbol. The method GetQuote has an input that takes in two parameters Stock Symbol and License Key and returns the following information.

StockSymbol, LastTradeAmount, LastTradeDateTime, StockChange, OpenAmount, DayHigh, DayLow, StockVolume, PrevCls, ChangePercent, FiftyTwoWeekRange, EarnPerShare, PE, CompanyName.

Link to webservice: http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?op=GetQuote WSDL of the webservice: http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDL Download WSDL from the above link. 1. Configurations at the Sender System (SAP R/3) 1.1 Create RFC destination: To create the RFC go to TCODE: SM59 Create new destination of type T (TCP/IP)

Make sure you select Registered Server Program option before writing your program ID Write your program ID (remember it's case-sensitive) In the gateway host and gateway service write the values of your "Application system" - business system (R/3 System)

1.2 Create Remote function module Create Remote Function module in R/3 system with the following parameters. Import:

Export:

Source code:

1.3 Create Report Program Create a report program in the R/3 system which makes Synchronous call of a remoteenabled function module ZN_GET_QUOTE. Code snippet REPORT ZTEST_WEBSERVICE. parameters: p_stsym(30). data: StockSymbol type char30, LastTradeAmount type char30, LastTradeDateTime type char30, StockChange type char30, OpenAmount type char30, DayHigh type char30, DayLow type char30, StockVolume type char30, PrevCls type char30, EarnPerShare type char30, companyname type char30, QuoteError type char30.

CALL FUNCTION 'ZN_GET_QUOTE' destination 'RFC' EXPORTING ST_SYM = p_stsym LKEY = '0' IMPORTING StockSymbol = StockSymbol LastTradeAmount = LastTradeAmount StockChange = StockChange OpenAmount = OpenAmount DayHigh = DayHigh DayLow = DayLow StockVolume = StockVolume PrevCls = PrevCls EarnPerShare = EarnPerShare companyname = companyname QUOTEERROR = QuoteError. if quoteerror NE 'true' and quoteerror NE 'TRUE'. write: /'StockSymbol:',StockSymbol, /'LastTradeAmount:',LastTradeAmount, /'LastTradeDateTime:',LastTradeDateTime, /'StockChange:',StockChange, /'OpenAmount:',OpenAmount, /'DayHigh:',DayHigh, /'DayLow:',DayLow, /'StockVolume:',StockVolume , /'PrevCls:',PrevCls, /'EarnPerShare:',EarnPerShare, /'companyname:',companyname, /'QuoteError:',QuoteError. else. write:/ 'Invalid Stock symbol'. endif.

Continued...

RFC-to-Web Service Scenario


...Previous 2. Configurations in the Integration Repository

2.1 Import the WSDL: Import the WSDL of the webservice as an External Definition; these structures are needed as we need to accomplish the mapping between the RFC.Request to SOAP.Request and SOAP Response to RFC Response.

Note: Usually when we import the WSDL as an External Definition, we get the relevant messages for the request and response structures along with it.

2.2 Import RFC

Import the RFC ZN_GET_QUOTE created in the previous step from R/3 system.

Note: Usually when we import the RFC from R/3 system, we get the relevant messages for the request and response structures along with it. 2.3 Define Message Interface As imported WSDL and RFC messages can be used as Data types, Message types and outbound message interface we dont require creating those. Define inbound synchronous message Interface

2.4 Create Message Mappings Here we need to create two mappings, first between RFC Request (ZN_GET_QUOTE.Request) to SOAP Request (GetQuoteSoapIn) and second between SOAP Response (GetQuoteSoapOut) to RFC Response (ZN_GET_QUOTE.Response).

2.5 Define Interface Mapping Define Interface mapping for the above created mappings. Request mapping

Response mapping

Continued...

RFC-to-Web Service Scenario


...Previous 3. Configurations in the Integration Directory 3.1 Create sender communication channel Create Sender Communication channel (RFC adapter) under the Sender Business system

Make sure the Program id specified here and the Program id specified in the RFC destination created above are same. 3.2 Create receiver communication channel Create Receiver communication channel (SOAP adapter) under the Receiver business service.

We need to specify the following in the SOAP adapter; 1. Target Url : http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDL 2. Configure Proxy: If your network has a proxy setup you need to provide the details of the same. 3. Configure proxy User Authentication: to be specified in case. 4. SOAP Action: we can find out the SOAP Action for the GetQuote method of the Webservice DelayedStockQuote in WSDL.

3.3 Create Sender Agreement Sender adapter in the sender agreement converts the message into XML format

3.4 Create Receiver Agreement Receiver Agreement defines to which receiver the message, has to be routed.

3.6 Create Interface Determination Interface Determination identifies the Mapping between the sender interface and Receiver interface.

3.5 Create Receiver Determination Receiver Determination defines the possible receivers for a sender and an outbound interface combination.

4. Testing the Scenario In the Sender R/3 system Execute the Report program we have created earlier. When the program is executed with Stock symbol it should get the details of that stock symbol from the Webservice. Below is the screenshot of the output we got when the program is executed with the StockSymbol R

Potrebbero piacerti anche