Consuming Webservices with tag in WSDL using ABAP
Consuming Webservices with tag in WSDL using ABAP
Have you ever generated a consumer proxy for a .NET web service and ended up with an empty output. I did and I found a few others on SDN who did. After you look around some more, you might find that the consumer proxy generation doesn't support certain XML tags in the WSDL. One of these Tags is
Background
There are several weblogs and help files describing the process of how to consume a web service in ABAP. I followed one of these guides to consume a web service that was generated using .NET in our company. The web service needs an input date and produced a table output of five fields per row. Step 1 was to generate a consumer proxy using the URL for the WSDL of the .NET web service. The process worked like good cake and I had a consumer proxy with the ABAP class generated and activated. I was anxious to test it. I clicked the test icon in SE80 to realize that I needed a logical port. With some more help from the useful blogs on SDN, I was running SOAMANAGER to create my logical port. This was the first stumbling block where the logical port creation based on URL didn't work and the SDN blogs didn't give me a solution. I was able to create the logical port using the manual configuration option (details to follow in a future blog). Back to testing the consumer proxy, I fill in the date in system generated XML input template and Execute. No errors or SOAPFaultCode1 messages finally. I had done it. I clicked on the Output tab to see what I got back. My excitement quickly fizzled away to see a blank page. Then I checked the Original Response tab. The XML response from the web service was all there. Why was the output blanks and how do I get to the response?
Root Cause for blank output
A consumer proxy does three main jobs:
- 1. Converts input parameters from ABAP format to XML format
- 2. Invokes the web service with XML request and receives output in XML format
- 3. Converts received XML response into ABAP data types
The ABAP to XML and XML to ABAP conversions of Step 1 and Step 3 are done using Transformations (extensive help available in SAP help). These transformations are generated during the consumer proxy generation process. In my scenario above the transformation for Step 3 did not give me the output I was looking for. It turns out that the cause of the problem was the web service WSDL itself. The WSDL used
Solution - Call a webservice with XML input and get XML output back
The solution doesn't go into the details of XML programming or input/output conversion of ABAP to XML or XML to ABAP. There are several blogs around that topic on SDN. What I describe here is an ABAP class that calls the consumer web service with input XML request and receives the XML response. The XML response can be processed by the calling ABAP program as needed.
ZWS_CALL ABAP Class
Create a class ZWS_CALL with one method as shown below. No attributes are needed.
Method signature
Importing | CLASS | TYPE | SEOCLNAME |
|
|
Importing | METHOD | TYPE | SEOCLNAME |
|
|
Importing | LOGICAL_PORT | TYPE | PRX_LOGICAL_PORT_NAME |
|
|
Importing | INPXML |
| TYPE | XSTRING | Request XML |
Exporting | RESXML | TYPE | XSTRING | Response XML |
|
Exception | CX_AI_SYSTEM_FAULT | Application Integration: Technical Error |
|
|
|
Method Code
method WS_CALL.
|
Sample program that uses the ZWS_CALL
constants: * Step 1 CALL TRANSFORMATION source_transformation *Step 2 * Step 3 |
Conclusion
Even in a less than perfect world, SAP can easily consume web services. ABAP Consumer proxy generated class can be used to accomplish parts of the job that it is intended to do. By combining simple XML processing ABAP commands with the generated consumer proxy, every web service can be consumed in ABAP.
References:
- 1. Consuming web service in ABAP
- a. http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/8086
- b. http://help.sap.com/saphelp_nw70/helpdata/en/47/3a989cbcef2f35e10000000a1553f6/frameset.htm
- 2. XML to ABAP and ABAP to XML Transformation -
- a. http://help.sap.com/saphelp_nw70/helpdata/en/e3/7d4719ca581441b6841f1054ff1326/frameset.htm