This wiki explains how to create web service from function modules (tcode SE37) and consume it in .NET (C#). This method usually is used when a non-SAP system (such as .NET) wants to interact with SAP. For example : for posting to FI. Let's follow the steps :
1. Create Function modules in SE 37. Go to tcode SE37. Enter the name of function modules and click button Create
2. Enter description for this function module and Set the attributes to "Remote Enabled Module". if you want to generate web service, you must set the processing type to "Remote Enabled Module"
3. Go to the next tab. Click "Import" Tab. Enter Import parameter needed. You must tick "Pass by value" check box in function modules that will be used as web service. In this case the associated type for Header is ZUST_AGRI_POST_CH_VAL_HEADER.
here is the structure of ZUST_AGRI_POST_CH_VAL_HEADER.
4. Go to next tab. Click "Export" tab. Don't forget to tick "Pass by value" checkbox like step 3
5. "Changing" tab is empty. Go to next tab. Click "Tables" tab.
Here is the structure of ZUST_AGRI_POST_CH_VAL_ITEM
6. Go to the last tab. Click "Source code" tab. Copy these codes.
7. Save the codes, assign to package and new Transport request number, then activate the function modules.
8. Next steps are generating the web service. Click "Utilities" -> "More Utilities" -> "Create web service" -> "From Function module"
9. Then "Provide Service Definition details" shows up. Enter web service name and its description, then click Continue. Usually I add "WS" to the prefix to differentiate the web service name and function module name.
10. On step "Choose Endpoint", just leave as it is. Click continue.
11. Next, on step "Configure service", don't forget to tick "Deploy Service", then click continue
12. On step "Enter package/request", Enter your package and transport request no, then click continue
13. Done. Your web service is activated.
14. Next step, create endpoint via tcode SOAMANAGER. This tcode will open web configuration tools via your web browser. Remember your browser must be Internet Explorer , otherwise the system won't run well
14b. If you face any issues regarding cannot open the web configuration tools, read this step. If you have don't have any issues opening the web configuration tools, you can skip this step and please read step 15. The URL will be like this (http://devecc.indofood.co.id:8080/sap/bc/webdynpro/sap/appl_soap_management?sap-client=530&sap-language=EN) :
Usually the problem is your computer cannot recognize the domain such as devecc.indofood.co.id , to resolve this issue, you must open your hosts file on C:\Windows\System32\drivers\etc\hosts , Enter your [SAP IP][space][domainname] under the last line of the hosts file (example : 172.30.52.102 devecc.indofood.co.id) like this picture and don't forget to save
You can get your SAP IP via SAP GUI :
To test the connection , open command prompt, press [Windows]+R , type cmd
Enter this command to the command prompt : ping[space][yourdomainname] ,example : ping devecc.indofood.co.id . The result will return result similar like this if your computer successfully recognize the SAP server IP:
Refresh your page in internet explorer.
15. The web configuration tools will be shown like this.
16. Enter your SAP username and password
17. The web configuration tools will be shown. Click "Business Administration" tab, then click "Web service administration" link
18. Web Administration menu shows up. First, click dropdown "Search by", choose "Service". Second, enter your search pattern, example : ZUAGRICHWS*POST*. Last, click button "Go"
19. The result will be shown on the Search results table below. Usually only 5 results are shown. If the results is more that that, you can click up or down arrow on the bottom of the search results table (marked by blue circle). Choose your web service by clicking the left column of chosen row. The row will be highlighted like image below. Then click "Apply selection" button.
20. After that, "Detail of service definition" window will be shown. Usually there are two conditions:
- if the dropdown in the right most is empty, then it means the service endpoint hasn't been created. you have to create service first. It will be explain in the next steps.
- if the dropdown in the right most isn't empty, then it means the service endpoint has been created. Just click "Open WSDL document for selected binding" link to open your WSDL document. (or skip to step 25)
21. To create service endpoint, click "Configuration" tab, then click "Create service"
22. Enter new service name (I give the same name as web service name, ex: ZUAGRICHWS_POST_AMOUNT), enter description , and enter new binding name (ex : ZUAGRICHWS_POST_AMOUNT). Then click apply settings
23. "Configuration of Web service" window shows up below the "Detail of service definition" window. Tick "User ID/Password" on HTTP Authentication box until "Collected Authentication method" have one row in its table. Then click Save button.
24. Notice that one new row appear on the "Detail of Service definition" table. Click "Overview" tab
25. Notice that the right most dropdown is not empty anymore. You have successfully created your endpoint. Click "Open WSDL for selected binding" link to open your WSDL document
26. The WSDL document URL will be similar like this : http://devecc.indofood.co.id:8080/sap/bc/srt/wsdl/bndg_4C73AADA27CC02CCE1008000AC1E3466/wsdl11/allinone/ws_policy/document?sap-client=530 , the content will be similar like image below.
28. Change some parts of the wsdl file to fix the bugs before it's consumed by .NET (by using text editors like notepad/ Textpad / Visual Studio).
31. Your web service has been successfully deployed :D Now Open your visual studio 2008. Add web reference from this web service
Enter your web service URL, click Go, then enter your web reference name that will be used in the code (ex : SAPWSD530POST), Click "Add reference"
32. Use this code
SAPWSD530POST.ZUAGRICHWS_POST_AMOUNT4 s = new SAPWSD530POST.ZUAGRICHWS_POST_AMOUNT4();
33. That's it. Just test using above codes. Customize the codes according to your needs. It works well in my system. Hope this tutorial helps.