Beginning SharePoint 2010 Development: Fix for Chapter 2 Web Services Soap Exception

A couple of you have experienced a Web service call error (Unauthorized Exception) in Chapter 2. The exception looks like the following:

System.Web.Services.Protocols.SoapException was caught
Message=Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerExcepti on' was thrown.
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String methodName, Object[] parameters)
at WPFListApp.MYSPWebReference.Lists.GetListAndView(S tring listName, String viewName) in C:\Users\Administrator\documents\visual studio 2010\projects\WPFListApp\WPFListApp\Web References\MYSPWebReference\Reference.vb:line 262
at WPFListApp.MainWindow.btnUpdate_Click(Object sender, RoutedEventArgs e) in C:\Users\Administrator\documents\visual studio 2010\projects\WPFListApp\WPFListApp\MainWindow.xam l.vb:line 68

I just wanted to post an amendment that may help you get through this sample. Replace the commented out line of code below with the other two lines of code where you’re setting UseDefaultCredentials and PreAuthenticate to true.

/* myListService.Credentials = System.Net.CredentialCache.DefaultCredentials; */

            myListService.UseDefaultCredentials = true;

            myListService.PreAuthenticate = true;

The full code listing for the XAML code-behind is as follows:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;

namespace WPFListApp
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        string strCompanyName = "";
        string strRegion = "";
        string strSize = "";
        string strSales = "";
        string strListID = "";
        string strViewID = "";

        public MainWindow()

        private void btnExit_Click(object sender, RoutedEventArgs e)

        private void btnUpdate_Click(object sender, RoutedEventArgs e)
            strCompanyName = txtbxCompanyName.Text;
            strRegion = txtbxRegion.Text;
            strSize = txtbxSize.Text;
            strSales = "$" + txtbxSales.Text;

            WPFListApp.MySPWebService.Lists myListService =
            new MySPWebService.Lists();
            //myListService.Credentials =

            myListService.UseDefaultCredentials = true;
            myListService.PreAuthenticate = true;

            myListService.Url = "";
            XmlNode myListView = myListService.GetListAndView("Customers", "");
            strListID = myListView.ChildNodes[0].Attributes["Name"].Value;
            strViewID = myListView.ChildNodes[1].Attributes["Name"].Value;
            XmlDocument myListDoc = new XmlDocument();
            XmlElement batchXML = myListDoc.CreateElement("Batch");
            batchXML.InnerXml = "<Method ID = '1' Cmd='New'><Field Name='Title'>" +
            strCompanyName + "</Field><Field Name='Region'>" + strRegion +
            "</Field><Field Name='Size'>" + strSize +
                "</Field><Field Name='Sales'>" + strSales +
            "</Field>" + "</Method>";
            XmlNode myListReturn = myListService.
            UpdateListItems(strListID, batchXML);
            MessageBox.Show("SharePoint List was updated!");

        private void btnClear_Click(object sender, RoutedEventArgs e)
            txtbxCompanyName.Text = "";
            txtbxRegion.Text = "";
            txtbxSales.Text = "";
            txtbxSize.Text = "";

I’ve added the full code sample here: Note that I will post any supplements, errata or additional code to this blog and add to the aforementioned folder.

Thanks to Jason for pointing this out!


Comments (4)
  1. sema atavi says:

    we get soap exception on search.asmx when we upgraded from 2007 to 2010. seems like LIKE keyword in the sql query is creating an issue.

  2. David Tran says:

    I use the code that you posted, but I still get the following error message:

       exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown


      XmlNode myListView = myListService.GetListAndView("Customers", "");

    Is there anything else I should try?


  3. Simple test, but is the name of your list Customers? Also, you may want to test the service to make sure it works outside of the application. I would start with these.


Comments are closed.

Skip to main content