Transcription

Consuming SAP Enterprise Services in a Microsoft OfficeConsuming SAP Enterprise Services in a Microsoft OfficeInfoPath FormApplies to: SAP Enterprise SOAMicrosoft Office InfoPath 2007Technical consultants, developersSummaryThis article demonstrates interoperability features of SAP Enterprise SOA in its integration with MicrosoftOffice tools. It introduces a sample InfoPath form template that consumes SAP Enterprise Services toretrieve information from back-end systems.Authors: Tarnoruder Anne, SAP NetWeaver Product Management, SAP Labs IsraelDudu Benabou, Microsoft Consulting Services, Microsoft IsraelCompany: SAPCreated on: February 2007Authors BioAnne Tarnoruder is a part of the SAP NetWeaver Product Management team in SAP Labs,Israel, responsible for knowledge transfer in the areas of PDK for .NET and Visual ComposerSDK. Prior to joining SAP in 2004, she held a number of positions in software development,team management, system architecture and technical communications in various high-techcompanies. Anne holds an M.S. degree in Applied Mathematics.Dudu Benabou is a solution architect working as part of MCS (Microsoft Consulting Services)at Microsoft Israel for the Microsoft - SAP alliance, serving as a contact for Microsoft productgroups in SAP Labs Israel and representing Microsoft Global ISV group.SAP DEVELOPER NETWORK sdn.sap.combpx.sap.com 2006 SAP AGBUSINESS PROCESS EXPERT COMMUNITY 1

Consuming SAP Enterprise Services In A Microsoft Office Infopath Form.DocTable of ContentsIntroduction . 3About Microsoft Office InfoPath 2007. 3About SAP Enterprise SOA and Enterprise Services . 3Prerequisites. 3Application. 4Implementation. 4Designing the Expense Report Form . 4Creating the Service Class . 8Finalizing and Distributing the Form Template. 11Testing the Form . 13Copyright . 15SAP DEVELOPER NETWORK sdn.sap.com 2006 SAP AGbpx.sap.com2

Consuming SAP Enterprise Services In A Microsoft Office Infopath Form.DocIntroductionThis article demonstrates interoperability features of SAP Enterprise SOA (Service Oriented Architecture)in its integration with Microsoft Office tools. It introduces a sample Microsoft Office InfoPath 2007 formtemplate that consumes SAP Enterprise Services to implement a business process.About Microsoft Office InfoPath 2007Microsoft Office InfoPath 2007 is an information-gathering program included in the 2007 release of theMicrosoft Office system. With it, you can create and deploy electronic forms to gather information efficientlyand reliably. You can also use the InfoPath Forms Services capabilities in Microsoft Office SharePointServer 2007 to extend your business processes beyond your corporate firewall, delivering forms asMicrosoft Office Outlook e-mail messages, Web browser forms, or forms for mobile devices.About SAP Enterprise SOA and Enterprise ServicesSAP Enterprise SOA is a blueprint for an adaptable, flexible, and open IT architecture for developingservice-based, enterprise-scale business solutions. With SAP NetWeaver as a technical foundation,enterprise SOA moves IT architectures to higher levels of adaptability by elevating Web services to anenterprise level.An enterprise service is typically a series of Web services combined with business logic that can beaccessed and used repeatedly to support a particular business process. Aggregating Web services intobusiness-level enterprise services provides a more meaningful foundation for the task of automatingenterprise-scale business scenarios.SAP Enterprise Services Repository offers a rich collection of services in various business domains, suchas ERP, CRM or Financial Services. These services are published in the UDDI-compliant SAP EnterpriseServices Registry and are available via the standard Web services interface.Prerequisites Microsoft Office InfoPath 2007 (included with MS Office 2007 Ultimate, Professional Plus andEnterprise editions)Access to SAP enterprise servicesSAP DEVELOPER NETWORK sdn.sap.com 2006 SAP AGbpx.sap.com3

Consuming SAP Enterprise Services In A Microsoft Office Infopath Form.DocApplicationThe InfoPath Expense Report form is used by employees to report travel expenses. To facilitate thisbusiness process, the form retrieves the static employee-related information, such as contact andorganizational data from the back-end systems, and automatically populates the relevant fields.The form template consists of two components representing the separate presentation and businesslayers: an interactive form and a class that implements the business logic by accessing enterprise servicesvia their standard Web service interface. This class invokes service interfaces exposed by Web serviceproxies, automatically created by the development environment.The form template is packaged for distribution either by email, or by deployment to a network location or toSharePoint services, where users can access it.The following diagram illustrates the architecture of the Expense Report form template application.Microsoft OfficeInfoPath 2007Expense ReportForm templateWeb serviceWeb ImplementationThe following section takes you through the steps required to implement and distribute the Expense Reportform template. For the purposes of this implementation, we will select and customize an existing sampleform template.Designing the Expense Report Form1. Start Microsoft Office InfoPath 2007.2. In the Getting Started dialog box, double-click Sample Expense Report. The Expense Reportform template opens in the design board.3. Rearrange the layout, fields and their labels so that the form template looks as follows:SAP DEVELOPER NETWORK sdn.sap.com 2006 SAP AGbpx.sap.com4

Consuming SAP Enterprise Services In A Microsoft Office Infopath Form.Doc4. Map the fields in the form to the XML schema in the Data Source panel. To open the panel, select View Data Sources .SAP DEVELOPER NETWORK sdn.sap.com 2006 SAP AGbpx.sap.com5

Consuming SAP Enterprise Services In A Microsoft Office Infopath Form.Doc5.Attach an event handler to the UserID field by right-clicking it and selecting Programming ChangedEvent. A Microsoft Visual Studio Tools for Applications window opens with the form code-behind module.The event handler declaration is added automatically:public void nseReport/my:employee/my:userID"].Changed new XmlChangedEventHandler(sapName Changed);}6.Create a simple login form by right-clicking the SAP Expense Report project in the Project Explorer andselecting Add New Item Windows Form. Name the form Login. Drag and dropcontrols onto the form so that it looks as follows:SAP DEVELOPER NETWORK sdn.sap.com 2006 SAP AGbpx.sap.com6

Consuming SAP Enterprise Services In A Microsoft Office Infopath Form.Doc7. In the event handler, add code to show the login form, receive user credentials and call theFillFormWithData function to retrieve the data from the wrapper component and populate theform.public void sapName Changed(object sender, XmlEventArgs e){// show login formLogin loginDialog new Login();loginDialog.UserName e.NewValue;loginDialog.ShowDialog();if (loginDialog.FormCancel true)return;string userName loginDialog.UserName;string password loginDialog.Password;loginDialog.Dispose();// Fill the form with data from SAP back-end systemFillFormWithData(userName, password);}SAP DEVELOPER NETWORK sdn.sap.com 2006 SAP AGbpx.sap.com7

Consuming SAP Enterprise Services In A Microsoft Office Infopath Form.DocCreating the Service ClassThe Service class encapsulates business logic provided by the enterprise services, in this case retrieval ofemployee and organizational data from the underlying back-end system. The class exposes the propertiesand methods used by the form code.1. Open the SAP Expense Report project by selecting Tools Programming Microsoft Visual StudioTools for Applications from the main menu.2. Right-click the project in the Project Explorer and select Add Web reference In the dialog box thatopens, provide a URL to the service and the login credentials.SAP DEVELOPER NETWORK sdn.sap.com 2006 SAP AGbpx.sap.com8

Consuming SAP Enterprise Services In A Microsoft Office Infopath Form.Doc3.Add a reference to each of the following enterprise services:Enterprise ServiceWorkAgreementSimpleByElementsQueryResponse InEmployeeNameByEmployeeQueryResponse InEmployeeCommunicationDataByEmployeeQueryResponse yeeQueryResponse anisationalCentreQueryResponse Response InServiceDescriptionReads an employee's work agreementIDs according to certain selection criteria.The output of the service is used as aninput parameter for other services.Returns employee names, form ofaddress and other related parameters.Returns employee contact information,such as phone numbers, email and fax.Returns employee organizational centerinformation, such as organizational unitand its location.Returns employee cost centerinformation.Returns an employee’s manager nameand contact information.Local Web service proxies are created automatically when a Web reference is added.Currently SAP supports only the Document style of WSDL, and not the Microsoft-specific RPC style, whichcauses a problem when consuming SAP services in the Microsoft environment. In this example, you needto apply a workaround that involves a minor correction of locally-stored WSDL files:a. In the Project Explorer toolbar, click the Show all files icon and expand the Web referencefolder.b. For each Web reference in the project, perform the following steps:c. Open the WSDL file, replace all instances of wsdl:part name "parameters" with wsdl:part name "parameter” (remove the s in parameters) and save the file.d. Right-click the Reference.map file and choose Run Custom Tool to invoke a utility thatgenerates code for XML Web services. This recreates the local proxy.4. Right-click the project in the Project Explorer and select Add Class. Add a class module.5. In the class, implement service calls to retrieve the necessary information. For example:public string EmployeeName(){if (!workAgreementExists)return "NA - no work agreement";ECC EmployeeNameByEmployeeQRService empNameService newECC redentials credentials;empNameService.Proxy webProxy;EmployeeNameByEmployeeQueryMessage empNameQueryMessage ryMessage.EmployeeNameSelectionByEmployee ameSelectionByEmployee.WorkAgreement ID newWorkAgreementID();SAP DEVELOPER NETWORK sdn.sap.com 2006 SAP AGbpx.sap.com9

Consuming SAP Enterprise Services In A Microsoft Office Infopath yEmployee.WorkAgreement ID.Value age empNameResponse empNameService.EmployeeNameByEmployeeQueryResponse In(empNameQueryMessage);string empName empNameResponse.Employee.Name.DeviatingFullName;if (empName null)empName "NA";return empName;}6. Go back to the form code-behind module and implement the FillFormWithData function toretrieve the data from the wrapper component and populate the fields of the form:private void FillFormWithData(string userName, string password){// initializing serviceSystem.Net.NetworkCredential credential newSystem.Net.NetworkCredential(userName, password);System.Net.WebProxy proxy new System.Net.WebProxy("proxy", 8080);service new ESCall(credential, proxy);workAgreement service.CreateWorkAgreement();// Call service to retrieve employee name and set the field valuestring serviceEmpName service.EmployeeName();XPathNodeIterator empName seReport/my:employee/my:name", Current.SetValue(serviceEmpName);//fill other fields }7. When done, build the project.SAP DEVELOPER NETWORK sdn.sap.com 2006 SAP AGbpx.sap.com10

Consuming SAP Enterprise Services In A Microsoft Office Infopath Form.DocFinalizing and Distributing the Form TemplateConfigure the submit options of the form to send an email to the employee’s manager. In the Submit ButtonProperties dialog box, set the email destination to the managerEmailAddress field.To enable the form to run in InfoPath, set the security options and digitally sign the content.1. Go to Tools Form Options and select Security and Trust.2. Choose the Full Trust option and the Sign this form checkbox.3. Click Select Certificate, select a certificate and cli