Wednesday, September 3, 2014

Using SoapUI to test SharePoint web services

SharePoint has number of built-in web services you can use for your integration projects. You can see the list here SharePoint 2010 Web Services .

To test them out you could use tool named SoapUI that allows you to build, send and receiver soap messages. I will give you instructions how to do that. First you should download SoapUI from http://www.soapui.org/  and go ahead and install it.

Launch the program. In the file menu you can create new SOAP project.


It will then ask you to insert a project name and show the location of a initial wsdl. I will name my project as SharePoint Web Services and give it a http://my-server:8000/_vti_bin/Lists.asmx?wsdl as an initial wsdl. List.asmx has several operations to manage your lists and librarys. It also a create idea to let it create sample requests fot the operations. For all the web services you can get their wsdl's by addint ?wsdl at the end of a address.


You are then prompted to insert credentials for your SharePoint site. After successful authentication you should see windows similar to this:


For this example i will use soap 1.2 operation named GetList. If i open up the sample Request 1 under GetList operation i can see the request that SoapUI has generated form me. I will change the "?" under listName value to "Documents", because i know i have such a library on that site. Clicking the arrow in the left upper corner of the windows will send the request.


If i send the request now i get 401 Unauthorized. SoapUI will not do NTLM authentication, so you need to set the right credentials in every request you make. To do that click on "Auth" button in the request window and select "Add New Authorization..." from the dropdown menu. Select NTML type.


After that you are asked for credentials with what you wish to perform that request. If you now hit run and everything goes well you should see the XML response with all the info about fields, views and other settings that the list has.


I have one more tip to save you from too much trouble - if you use operations like UpdateListItem where you need to define fields you are updating, always add Name and DisplayName to describe the field. Most of the time, adding Name is enough, but sometimes you get a nasty uninformative error and you spend an hour trying to understand why your request doesn't work.

9 comments:

  1. Thank you, thank you, thank you!!! I have been trying to figure out why I couldn't get any of my tests to work in SOAP UI and your tip on adding authorization is exactly what I needed!

    ReplyDelete
  2. Thank you very much! This really helped me a lot. :)

    ReplyDelete
  3. Is there any way to retrieve a file content from SharePoint ?

    ReplyDelete
  4. I am getting 403 Forbidden issue for SharePoint Online. Tried NTLM many times.

    ReplyDelete
  5. To find out your Sharepoint security settings: use FireFox or Chrome, open Developer tools (F12), open Network tab, browse to your Sharepoint, do FULL refresh (=Shift+F5). Now look in the Developer tools, tab Network, for the first response with a HTTP 200 (=OK) after a bunch of 401 (=NOT AUTH)

    ReplyDelete
    Replies
    1. Forgot to mention: the request header is called Authorization
      The first positions of its content shows the used method like:
      Authorization: NTLM XXX…XXXw==
      (in this case NTLM, can also be BASIC and many more)

      Delete
  6. For those struggling with this, I solved it like this:

    In your browser (Chrome/Firefox or other that has a developer console) Open your sharepoint online site, then select the first loaded page, in my case (https://[mydomainname].sharepoint.com/sites/[NameOfSite]) and then under Application -> Cookies, I select the same site as my sharepoint site.
    There are two cookies you need, the rtFa and the FedAuth, they are added as headers to your SoapUI request.

    Auth: None
    And then under headers create a header called Cookie, and add the two cookies as rtfa=[value of rtFa cookie];FedAuth=[value of FedAuth cookie]

    And then execute the request.

    ReplyDelete