How to build web service and push on sharepoint
Open visual studio 2010 | New Project
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
Open Service1.asmx.cs and view default code
Typing F5 and click to method HelloWorld
Click Invoke
Result as follow
Right click Project | properties
Choose Category Application then click to button Assembly
information …
Fill full information, then click ok
Continue, choose category Signing
Check to checkbox “Sign the assembly” and choose new strong name key from dropdownlist below
Input name’s key file name and uncheck “Protect my key file
with a password”
Copy Dll in bin folder of your project (drag and drop to bin
folder to assembly folder)
After copy dll to here, right click to .dll | properties
Copy Public token key below and paste anywhere example
notepad
Open Service1 by notepad (Image 15)
You will see class as follows
Append this segment code “,
HelloWord,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=140f54b64af2de0f”
in class as follow
Copy service1 to folder “C:\Program Files\Common
Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS” as follows
Open visual studio command prompt (2010) and input cd c:\ and type enter
Input: Disco http://quochung-axioo:90
/_layouts/Service1.asmx
After Disco successful, automatically the service1.asmx will
push on sharepoint
How to call web service by web part
New Visual Webpart
Choose “Deploy as a farm
solution”
Right click to reference | Add Service Reference …
Click button Add Web Reference…
Login by administrator account of sharepoint
Open visualWebpartUserControl.ascx | drag and drop literal to here
Copy this segment code to Page_Load event as follows:
HelloWordService.Service1 helloWord = new HelloWordService.Service1();
Literal1.Text= helloWord.HelloWorld();
Build and deploy project you will meet error
Go to Central Admin |
click to “Manage web applications” link then click to your web application – On
ribbon choose Icon Authentication Provides (Image 35)
Dialog appear, click to “Default” link
Check to “Enable anonymous access”
Back to list your application, on you web application choose
Icon Anonymous Policy on ribbon
In anonymous User Policy:
choose radio button “None - policy”
Go to your web application
Site Actions | Site Settings | Site Permissions
On ribbon click Icon Anonymous Access
In Anonymous user can access: choose “Entire Web site”
Refresh page which contain webpart call web service and you
see result display as follows
