Testing the Web Method

Now that you've added the code to your solution, you'll want to test out the Service to make sure it works. To test out the code:

1. Change the SPSite value to your own SharePoint default site (if you didn't use the GetContextSite method) and add a list called Survey to SharePoint with two fields called Question and Answer. To do this, navigate to your SharePoint site, click ''View All Site Content,'' and click Create. Under Custom Lists, click ''Custom List,'' and provide a name and description and click OK. To add columns to the list, open the list and click ''Site Settings'' and ''Create Column.'' Add a column of type ''Single line of text'' called Question and another column of the same type called Answer. You can manually enter a question at this point, so go ahead and do that, but leave the Answer field blank and then come back to the Visual Studio Web Service project.

2. Hit [F5]. You'll be prompted to enable script debugging (for IE).

3. Click Yes to continue. At this point, Visual Studio will open an instance of Internet Explorer and load the Web Service. Figure 3-12 shows what this page looks like. In the upper-left-hand portion of the page, you'll see the web methods that are in your Web Service. Because you only include one, called updateLikertList, this is the only web method that is listed on the page.

4. If you click on the web method, this will open another page where you can test the invocation of the web method (see Figure 3-13). Note here that the input parameter called userResponse is the one you created in the method instance in the Visual Studio project. Enter one of the values from the Likert scale (i.e., Strongly Agree, Agree, Neutral, Disagree, or Strongly Disagree), and then click Invoke.

5. When you click on the Invoke button, this will update the Answer field in the Survey list (which you manually created) in your SharePoint site. Figure 3-14 displays the updated field labeled 1 — your code translated the ''Strongly Agree'' string into a string value of 1 and then updated the list field with that value.

0 0

Post a comment

  • Receive news updates via email from this site