1. Open visual studio 2010 | New Project.
2. On Web template, choose .NET Framework 3.5 from dropdownlist then choose ASP.NET Web Service Application project and provide name is HelloWorld.
Structure of project as follows.
3. Open Service1.asmx.cs and view default code.
4. Typing F5 and click to method HelloWorld.
5. Click Invoke.
Result as follow.
6. Right click Project | properties
Choose Category Application then click to button Assembly information.
7. Fill full information, then click ok.
8. Continue, choose category Signing.
9. Check to checkbox “Sign the assembly” and choose new strong name key from
dropdownlist below.
10. Input name’s key file name and uncheck “Protect my key file with a password”.
11. Copy Dll in bin folder of your project (drag and drop to
bin folder to assembly folder.
12. After copy dll to here, right click to .dll | properties.
13. Copy Public token key below and paste anywhere example notepad.
14. Open Service1 by notepad (Image 15).
15. You will see class as follows.
16. Append this segment code “,
17. Copy service1 to folder “C:\Program Files\Common Files\Microsoft Shared\Web
Server Extensions\14\TEMPLATE\LAYOUTS” as follows.
18. Open visual studio command prompt (2010) and input cd c:\ and type
enter.
19. Input: Disco http://quochung-axioo:90 /_layouts/Service1.asmx
20. After Disco successful, automatically the service1.asmx will push on sharepoint.
21. Type link http://quochung-axioo:90 /_layouts/Service1.asmx on address bar and see result as follows.
How to call web service by web part
22. New Visual Webpart
23. Choose “Deploy as a farm solution”
24. Right click to reference | Add Service Reference …
25. Click button Advanced…
26. Click button Add Web Reference…
27. Paste “http://quochung-axioo:90 /_layouts/Service1.asmx” to URL then click button GO
28. Login by administrator account of sharepoint
29. Click Add reference
30. Web services was added
31. Open visualWebpartUserControl.ascx | drag and drop literal to here
32. Copy this segment code to Page_Load event as follows:
HelloWordService.Service1 helloWord = new HelloWordService.Service1();
Literal1.Text= helloWord.HelloWorld();
33. Build and deploy project you will meet error
34. How to solve
36. Check to “Enable anonymous access”
37. Back to list your application, on you web application choose Icon Anonymous
Policy on ribbon
38. In anonymous User Policy: choose radio button “None - policy”
39. Go to your web application
42. Refresh page which contain webpart call web service and you see result display
as follows
2. On Web template, choose .NET Framework 3.5 from dropdownlist then choose ASP.NET Web Service Application project and provide name is HelloWorld.
Result as follow.
Choose Category Application then click to button Assembly information.
HelloWord, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=140f54b64af2de0f”
in class as follow.How to call web service by web part
22. New Visual Webpart
26. Click button Add Web Reference…
HelloWordService.Service1 helloWord = new HelloWordService.Service1();
Literal1.Text= helloWord.HelloWorld();
Go to Central Admin | click to “Manage web applications”
link then click to your web application – On ribbon choose Icon Authentication
Provides
35. Dialog appear, click to “Default” link
Site Actions | Site Settings | Site Permissions
40. On ribbon click Icon Anonymous Access
41. In Anonymous user can access: choose “Entire Web site”
No comments:
Post a Comment