Generate Webservice With SAP Netweaver

19
Alex Maier How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Serv ava !! " !dition How to Generate a Web Service Client with SAP NetWeaver Application Server Java EE 5 Edition Applies to: SAP NetWeaver Application Server Java EE 5 Edition https://www.sdn.sap.com/irj/sdn/downloads?rid=/lirar!/""id/da#$$d%&'(()' (()('$$('*))+5,*-)e*% Access to the ES Wor place m!SAP E P E00 #(( https://www.sdn.sap.com/irj/sdn/developerareas/esa/eswor place Summar 1his doc"ment enales !o" to 2enerate We Service 0lients *or cons"min2 We Services *rom the ES Wor place "sin2 the SAP NetWeaver 3eveloper St"dio. 4or ease o* "se this 2"ide is divided into *o"r parts: part one descries the re6"ired project part two deals with choosin2 and importin2 a WS37 *i three involves 2eneratin2 the We Service 0lient and part *o"r tests the Service 0lient with a JavaServer Pa2e. 1he time re6"irement *or this how'to 2"ide is ao"t %5 min"tes. Author: 8oris 9"eller Compan: SAP ACreated on: )# Jan"ar! %((& Author !io 8oris 9"eller is comp"ter science st"dent and wor s at present as a trainee SAP in the 9ar et 3evelopment En2ineerin2 1eam in Walldor*. 8oris has several !ears e;perience as maintenance s"pervisor o* electrical en2ineerin2 and telecomm"nications in a mana2ement position.

description

Webservice für SAP generieren

Transcript of Generate Webservice With SAP Netweaver

Alex Maier

How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition How to Generate a Web Service Client with SAP NetWeaver Application Server Java EE 5 Edition Applies to: SAP NetWeaver Application Server Java EE 5 Edition https://www.sdn.sap.com/irj/sdn/downloads?rid=/library/uuid/da699d27-0b01-0010-99b0-f11458f31ef2 Access to the ES Workplace mySAP ERP ECC 600 https://www.sdn.sap.com/irj/sdn/developerareas/esa/esworkplace Summary This document enables you to generate Web Service Clients for consuming Web Services from the ES Workplace using the SAP NetWeaver Developer Studio. For ease of use, this guide is divided into four parts: part one describes creating the required project, part two deals with choosing and importing a WSDL file, part three involves generating the Web Service Client, and part four tests the Web Service Client with a JavaServer Page. The time requirement for this how-to guide is about 25 minutes. Author: Boris Mueller Company: SAP AGCreated on: 16 January 2007 Author Bio Boris Mueller is computer science student and works at present as a trainee at SAP in the Market Development Engineering Team in Walldorf. Boris has several years experience as maintenance supervisor of electrical engineering and telecommunications in a management position. SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 1 Table of Contents Applies to: ........................................................................................................................................ 1 Summary.......................................................................................................................................... 1 Author Bio ........................................................................................................................................ 1 Table of Contents ............................................................................................................................ 2 Part 1: Creating a Project ................................................................................................................ 3 Create a Dynamic Web Project 2.5.............................................................................................. 3 Use ........................................................................................................................................... 3 Procedure ................................................................................................................................. 3 Create an Enterprise Application 5 Project .................................................................................. 3 Use ........................................................................................................................................... 3 Procedure ................................................................................................................................. 3 Part 2: Choosing and Importing a WSDL File.................................................................................. 3 Choose a WSDL file..................................................................................................................... 3 Use ........................................................................................................................................... 3 Procedure ................................................................................................................................. 4 Import a WSDL File ......................................................................................................................... 4 Use ........................................................................................................................................... 4 Procedure ................................................................................................................................. 5 Part 3: Generating a Web Service Client......................................................................................... 5 Use ........................................................................................................................................... 5 Procedure ................................................................................................................................. 5 Part 4: Testing the Web Service Client............................................................................................ 7 Creating a JavaServer Page (JSP).............................................................................................. 7 Use ........................................................................................................................................... 7 Procedure ................................................................................................................................. 7 Creating source code ................................................................................................................... 7 Use ........................................................................................................................................... 7 Procedure ................................................................................................................................. 7 Deploy the JavaServer Page ..................................................................................................... 10 Use ......................................................................................................................................... 10 Procedure ............................................................................................................................... 10 Complete source code for the JSP ............................................................................................ 11 Related Content............................................................................................................................. 13 Copyright........................................................................................................................................ 14 SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 2 How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition Before you create web components, you need to create a Dynamic Web Project 2.5. The purpose of this project type is to organize and collect the web components of a Java EE 5 application. All class files, resources and deployment descriptors that are to be packed in the same web archive (WAR) should be created in the same Dynamic Web Project 2.5. To create the project, complete the following steps: Procedure 1. Choose File New Project.2. In the pop-up window, choose Web DynamicWeb Project 2.5.3. Enter the project name: WsClient.4. Choose Finish to create a new Dynamic Web Project. Create an Enterprise Application 5 Project Use To create enterprise applications in SAP NetWeaver Developer Studio, you use Enterprise Application Projects 5. The goal of this project type is to assemble all Web, EJB, connector and other components (modules) of the application. The application components represented by their corresponding projects - for example, the EJB components of an application are represented by the corresponding EJB 3.0 Project. An Enterprise Application Project 5 also allows you to add bundled libraries to the application. To create the project, complete the following steps: Procedure 1. Choose File New Project.2. In the pop-up window, choose J2EE Enterprise Application 5 Project. 3. Choose Next.4. Enter the project name: EarProject5. Choose Finish to create a new Enterprise Application 5 Project.. Part 2: Choosing and Importing a WSDL File Choose a WSDL file Use The Web Service Client Wizard needs a WSDL file to access the Web service. In the following example, we will use the Find Customer by Address Web service, which you can find on the ES Workplace. The name of this Web service in the mySAP ERP ECC 600 backend system is ECC_CUSTOMER002QR. To find and save this WSDL file, complete the following steps: SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 3 How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition

Part 1: Creating a Project Create a Dynamic Web Project 2.5 Use Procedure 1. Open the ES Workplace: http://erp.esworkplace.sap.com/socoview 2. Click the link Enterprise Service Index. 3. In the Search field of the resulting page, insert the name of the Enterprise Service: Find Customer by Address. Click Search. 4. In the browser window, the results of your search will appear. Click the link Find Customer by Address, which will give you more information about the Enterprise Service. 5. To open the WSDL file, click on the Related Web Service Definition link. 6. You will have to log on before accessing the WSDL file. Once you have logged in and have access to the WSDL file as XML, choose File Save As...in the browser window. Make sure that you change the file extension from XML to WSDL before saving the file locally. Import a WSDL File Use The Web Service Client Wizard will assist you in creating a new Web Service Client from a WSDL file. First, you have to import a WSDL file into your Dynamic Web Project. To do so, complete the following steps: SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 4 How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition Procedure 1. Choose File Import. 2. In the pop-up window, choose General File System and click Next. 3. Click Browse on the next page of the wizard to select the path which contains the WSDL file. 4. In the window on the right, select the checkbox for the WSDL file. 5. Specify the WsClient project as the import destination. 6. When you have finished specifying your import options, click Finish. Part 3: Generating a Web Service Client Use With the generated projects and the WSDL file, you can generate a Web Service Client. To generate a Web Service Client, complete the following steps: Procedure 1. Select the WSDL file from the WsClient project. 2. Right-click on the file name. In the pop-up menu, choose Web Services Generate Client. A wizard for creating a Web Service Client will start. 3. Choose the Client EAR project from Configuration. 4. In the pop-up window, change the name of the Client EAR project from WsClientEAR to EarProject and click OK. 5. Move the slider to the Start client position. 6. Check the settings under Configuration. The settings should be: - Server: SAP Server - Web service runtime: SAP Netweaver - Client project: WsClient - Client EAR project: EarProject 7. Once you are sure the settings are correct, choose Next.8. Choose the folder source in the WsClient project as the output folder and choose Finish. 9. Enter the user and password information for the engine and click OK. SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 5 How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition 10. If the deployment was successful, the following dialog will appear. Choose OK again. 11. The Deploy View Console will appear. In this Console, you can see the entire deployment process. The wizard has created two classes and two files: Java classes in the source folder, class files in the build folder, a WAR file, and an EAR file. The EAR file is deployed. SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 6 In the current preview version of SAP NetWeaver Application Server Java EE 5 Edition, the testing feature has not yet been implemented. Therefore, we must do the testing using a JavaServer Page (JSP). The JSP technology enables you to generate dynamic web content, such as HTML, DHTML, XHTML, and XML files, to include in a Web application. We will use a JSP to test the Web Service Client. Most types of JSP files can be created using the JSP File wizard. To create a basic JSP file using the wizard, complete the following steps: Procedure 1. Select the WebContent folder in the WsClient project. 2. From the WsClient context menu, choose New Other. 3. In the pop-up window, choose Web JSP and click Next. 4. On the next page of the wizard, enter the file name of the JSP: index. 5. Click Finish to create a Java Server Page File. Creating source code Use To invoke the Web service, you have to specify the proxy settings, authentifications, and values of the request and response. The process is described below, and the complete source code of the JSP is available at the end of this chapter. Procedure 1. Insert the imports. 2. Insert the title of the page3. Handle errors and exceptions with a try/catch statement into the body-tag SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 7 How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition

Part 4: Testing the Web Service Client Creating a JavaServer Page (JSP) Use

Test WS Client Webservice returns : 3. Insert the proxy settings when they are necessary 4. Create instances

System.setProperty("proxyHost", ""); System.setProperty("http.proxyHost", ""); System.setProperty("proxyPort", "my_proxy_port"); System.setProperty("http.proxyPort", "my_http_proxy_port");

// connection to the web serviceCustomerSimpleByNameAndAddressQueryResponseInService service = new CustomerSimpleByNameAndAddressQueryResponseInService(); // get method for web service portCustomerSimpleByNameAndAddressQueryResponseIn query = service.getCustomerSimpleByNameAndAddressQueryResponse_InSoapBinding(); // create requestCustomerSimpleByNameAndAddressQueryMessageSync message = new CustomerSimpleByNameAndAddressQueryMessageSync();// in memory representation of querydataCustomerSimpleByNameAndAddressQueryMessageSync. CustomerSimpleSelectionByNameAndAddress querydata = new CustomerSimpleByNameAndAddressQueryMessageSync. CustomerSimpleSelectionByNameAndAddress();OrganisationName oname = new OrganisationName();4. Insert authentication and specify your username and password from the ES Workplace. 5. Set values for the request. SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 8 javax.xml.ws.BindingProvider bp = (javax.xml.ws.BindingProvider) query; Map context = bp.getRequestContext(); context.put("javax.xml.ws.security.auth.username", "myUser"); context.put("javax.xml.ws.security.auth.password", "myPassword"); oname.setFirstLineName("Julia");oname.setSecondLineName("");oname.setThirdLineName(""); 6. Display the response. How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition

oname.setFourthLineName(""); querydata.setCustomerName(oname); querydata.setCustomerAddressCountryCode("DE"); querydata.setCustomerAddressCityName(""); querydata.setCustomerAddressDistrictName(""); querydata.setCustomerAddressStreetPostalCode(""); querydata.setCustomerAddressStreetName(""); querydata.setCustomerKeyWordsText(""); querydata.setCustomerAdditionalKeyWordsText(""); message.setCustomerSimpleSelectionByNameAndAddress(querydata);

CustomerSimpleByNameAndAddressResponseMessageSync responce = query.customerSimpleByNameAndAddressQueryResponseIn(message); List li = responce.getCustomer(); for (CustomerSimpleByNameAndAddressResponseMessageSync.Customer c : li) { %> Customer: Key Value CustomerID FirstLineName BlockedIndicator NaturalPersonIndicator SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 9 Deploy the JavaServer Page Use Before use, the JSP needs to be deployed as follows. Procedure 1. Select the EarProject and click the right mouse button. 2. From the context menu, choose Run As Run on Server. 3. In the pop-up window, choose your server and click Finish. 4. Enter the user and password for the engine and choose OK. 5. If the deployment was successful, a dialog will appear. Choose OK to deploy the JSP on the engine. 6. Choose OK to deploy the JSP on the engine. The result of the response will be displayed in your web browser. To start the JSP, enter the following address in your web browser: http://:/ In this example, the address is: http://localhost:50000/WsClient How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition

Customer: Key Value CustomerID FirstLineName BlockedIndicator NaturalPersonIndicator SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 12 How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition

oname.setSecondLineName("");oname.setThirdLineName("");oname.setFourthLineName("");querydata.setCustomerName(oname);

Related Content Platform Ecosystem ES Workplace homepage on SDN Enterprise SOA homepage on SDN How-To-Guide for generating a Web Service Client with the SAP NetWeaver Application Server Java EE 5 Edition SAP DEVELOPER NETWORK | sdn.sap.com 2007 SAP AG BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 13 No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation.UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. These materials are provided as is without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages. Any software coding and/or code lines/strings (Code) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent. SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 14