1,499 articles and 10,433 comments as of Friday, April 16th, 2010

Tuesday, November 3, 2009

Using XML Web Services in SharePoint Designer

Christopher QuickGuest Author: Christopher Quick
wssdevelopment.blogspot.com

I noticed that I had promised better details on a previous post, so I have decided to include step by step instructions on building a solution that queries an XML web service for data and displays that information in SharePoint 2007.

In the post, I described how I used SharePoint Designer to query an XML web service to build a course roster system for our professors. This is a very simple solution that allows a faculty member to go to SharePoint and display their courses and view the students enrolled in that course from data in our ERP system.

Starting in SharePoint designer, I open the site where this solution would be placed. The site I’m using has a Pages document library, but any document library should work.

XML Web Services in SPD

I need two pages: one to display the available courses and another to display the students enrolled in the course. A page can be created by right clicking on the window and choosing new aspx page. Following this process, I create these two pages: CourseRoster.aspx and StudentsInCourse.aspx.

XML Web Services in SPD

Now, the web service data sources need to be created. I begin by opening Manage Data Sources from the Data View menu. This opens the Data Source Library task pane. I locate the XML Web Services node and expand it. Next, I click on Connect to a web service…

XML Web Services in SPD

The data source properties window will open and show the Source Tab. To help identify this data source, I begin by going to the General Tab and providing a name that is more descriptive than the default one that will be created.

XML Web Services in SPD

On the Source tab, I provide the details on how to contact the web service, connect to the web service by clicking on Connect Now and select the appropriate method. (Notice that you do have the ability to use web services to update data as well, but this is beyond the scope of this post.). Any parameters that are needed for the web service will be displayed in the parameters box at the bottom of the dialog.

XML Web Services in SPD

So that I can customize the parameters sent to the web service, I need to make modifications to the parameters. I click on the parameters that will need to allow to be set dynamically and then click on Modify. In this case, the Login will need to be provided dynamically; However, for simplicity, I will only be using the default value for this data source.

When I click on Modify, the parameter properties dialog will open. I insure the checkbox for The value of this parameter can be set via a Web Part connection is checked and provide a default value to use for the initial query of the data source. When the values are set correctly, I click OK to close the dialog.

XML Web Services in SPD

If the web service required authentication, I would change properties on the Login tab. Fortunately, the web service that I am using does not require authentication, so I click OK to create the new data source.

XML Web Services in SPD

This data source will be used to get the list of courses for a specific professor. Since the same web service also has a method to get the students currently enrolled in the course, I can simply make a copy of this web service and modify the settings appropriately.

To do this, I right click on the web service I just created and choose Copy and Modify. Again, I change the name on the general tab to provide a better name for the data source. In my case, this one is called StudentsInCourseWebService. On the source tab, I click reconnect and choose the new method to use. Again, I need to modify the parameters. This web service method expects a parameter named SYN. This is the unique identifier of a course in our organization, so it will need to be provided dynamically.

XML Web Services in SPD

Now I have both of my web service data sources ready, it’s time to use the data! First, I open the CourseRoster.aspx page in SharePoint designer. A blank ASP.NET page is displayed. With the page active, I open the data source library task pane and locate the data source that queries the courses for the current professor. I right click on it and choose Show Data.

XML Web Services in SPD

This queries the web service using the default value and returns the results in the Data Source Details task pane. Now, I CTRL-Click on all the fields that will need to be displayed on the data source and then click on Insert Selected Fields as… > Multiple Item View

XML Web Services in SPD

The CourseRoster.aspx page now displays a list of available courses using the default value provided to the web service.

XML Web Services in SPD

I want the professor to be able to click on the course number to open the course and view currently enrolled students. To do this, I move the mouse cursor over one of the items in the CourseNumber row and look for the task widget (I’m not sure what the actual name of it is, but it’s a little gray arrow).

XML Web Services in SPD

I click on the widget and the properties of this field are be displayed. I need this to be a hyperlink, so I choose Hyperlink in the Format As dropdown.

XML Web Services in SPD

A message warning me hyperlinks should only be used in a trusted environment appears. I click Yes to confirm the creation of a hyperlink and the hyperlink properties window is displayed. I will leave the text to display as {CourseNumber}, but I need to change the Address to StudentsInCourse.aspx?SYN={SYN}. I confirm this by clicking on OK.

XML Web Services in SPD

I now move to the StudentsInCourse.aspx page and make sure it is the active page in SharePoint designer. I reopen the Data Source Library task pane to locate the data source that gets the students in a specific course. Right clicking on it, as before, I choose to Show Data. Again, I choose the columns to display and click on Insert Selected Items As Multiple Item View. There is now a list of students for the default value provided in the data source. This is not the desired result, so I need to specify a source for the parameter. I locate the widget for the data source and click on Parameters.

XML Web Services in SPD

The SYN parameter is available, I just need to specify the source. This is done be choosing Query String in the parameter source drop down and setting the Query String Variable to SYN.

XML Web Services in SPD

Now, it’s time for testing. To insure that everything is working, I save everything and go back to the CourseRoster.aspx page and click on the preview button on the toolbar.

XML Web Services in SPD

This opens Internet Explorer to the CourseRoster.aspx page with a list of courses. I can click on a specific course to view the students enrolled in the course.

XML Web Services in SPD

Finally, I need to apply the SharePoint master pages to these pages. To do this I go back to SharePoint Designer and click on Format > Master Page > Attach Master Page. I choose to attach the Default Master and match any content regions that need to be setup.

XML Web Services in SPD

When completed, the page is now wrapped in SharePoint. I do the same thing for the StudentsInCourse.aspx page and the solution is now complete.

XML Web Services in SPD

Christopher QuickGuest Author: Christopher Quick
wssdevelopment.blogspot.com

Christopher Quick is the SharePoint Administrator and Developer for Southwestern Baptist Theological Seminary in Fort Worth, TX. He has been an end-user and administrator of SharePoint since 2004 and began developing solutions for SharePoint in 2007.

 

Please Join the Discussion

9 Responses to “Using XML Web Services in SharePoint Designer”
  1. Jalpa says:

    Hi Christopher,

    Very helpful post! Thanks.

    I followed these steps. But when I try to show data, it gives me an error ‘The server returned non-specific error when trying to get data from the data source. Check the format and content of the query and try again. If the problem persists, contact the server administrator.’
    My web service contains complex data type. I am not sure what is causing this error.

    Please help.
    J

  2. Chris Quick says:

    Jalpa,

    Are you using a complex data-type for querying the web service? If you are, that may be the problem since the only types that work within SPD are going to be simple types like numbers, letters, dates, etc.

  3. Jalpa says:

    Hi Christopher,

    Thanks for your reply. I am using string,int,boolean and an array of string for querying the web service. Everything is working fine.

    How can I put validations on controls? Form web part only accepts html controls. I want to add validations using javascript. Is it possible?

    Thanks again,
    J

  4. Hemant says:

    Hi Chris,

    I am also facing the same issue, when I click on show data it says “The server returned non-specific error…”. Any idea what could be the reason?

    Regards,
    Hemant

  5. Jalpa says:

    Hi Hemant,

    In my case, everything was working fine. It shows this error on the page, but when you run it, it works. For me, It occured because I was not giving any default value, so response from web service was not proper. But when you run it and provide proper values to webservice method, I think it should work.

    HTH
    Jalpa

  6. Chris Quick says:

    In most cases, if you get an error from the server it is because some required information had not been provided. As Jalpa pointed out, you will need to make sure a default value is provided or you will get a non-specific error.

  7. Chris Quick says:

    Jalpa,

    You should be able to provide javascript, but I won’t be able to provide details. I would suggest looking into the jQuery library as it helps abstract away some of the difficulties of javascript — however, be sure you understand what the library is doing or you can have a performance killer on your hands.

  8. Hemant says:

    I have provided the required details where there are input parameters. In some cases there is no input value and still the error shows up. Another observation is this is not consistent, some web services show data some times and the error shows up after sometime. I tried with some external web services like City State Zip which will take the zip code input and returns the city and state. Such web services always show the error message though they are returning simple data.

  9. Jalpa says:

    Thanks very much Chris,

    I have solved my problem of javascript. Everything is working as expected!. :)

    Thanks again,
    Jalpa


Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!