Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a Sharepoint web service 1

Status
Not open for further replies.

andegre

MIS
Oct 20, 2005
275
US
I'm trying to call the Sharepoint web service "Lists.asmx". I'm getting the SoapOperation exception but it doesn't give the "message" other than that so I'm having trouble trying to find out where to start looking in my code.

Here's my C# code doing the call to the webservice:

Code:
            try
            {
                xJobList = SharePointService.GetListItems("Batch Job Information", null, xQuery, xQueryFields, "1000", xQueryOptions, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred retrieving the batch job information from Sharepoint.\r\n\r\n" + ex.ToString());
            }
            finally
            {
                SharePointService.Dispose();
            }

I populate the ViewFields and QueryOptions variables as XMLElements that come from my XML file which looks like this:

Code:
<BatchJobInformationQuery>
	<ViewFields>
		<FieldRef Name='Batch Job Name' />
		<!--<FieldRef Name='Tables Touched' />-->
	</ViewFields>
	<Query id='Default'>
    <OrderBy>
      <FieldRef Name='Batch Job Name' Ascending='TRUE' />
    </OrderBy>
    <Where>
      <Neq>
        <FieldRef Name='Batch Job Name' />
        <Value Type='Text'></Value>
      </Neq>
    </Where>
	</Query>
  <QueryOptions>
    <IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>
    <IncludeAttachmentUrls>FALSE</IncludeAttachmentUrls>
    <DateInUtc>TRUE</DateInUtc>
  </QueryOptions>
  <BogusResult>
    <listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
               xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
               xmlns:rs="urn:schemas-microsoft-com:rowset"
               xmlns:z="#RowsetSchema"
               xmlns="[URL unfurl="true"]http://schemas.microsoft.com/sharepoint/soap/">[/URL]
      <rs:data ItemCount="1">
        <z:row ows_Batch_Job_Name="No Name" />
      </rs:data>
    </listitems>
  </BogusResult>
</BatchJobInformationQuery>

And here's the Sharepoint service initialization:

Code:
        private wsSharepoint_Lists.Lists SharePointService
        {
            get
            {
                if (_sharePointService == null)
                {
                    _sharePointService = new BatchJobHistoryVisualizer.wsSharepoint_Lists.Lists();
                    _sharePointService.Url = "[URL unfurl="true"]http://portal/it/mvst/_vti_bin/lists.asmx";[/URL]
                    _sharePointService.PreAuthenticate = true;
                    _sharePointService.Credentials = System.Net.CredentialCache.DefaultCredentials;
                }

                return _sharePointService;
            }
        }

I'm not all that sure on the xml portion so I'm thinking that's the safest bet, but I've tried many different combinations with no success.

Any help is appreciated!
 
I've been working more on this today and have found some interesting information.

I started a Wireshark trace of the webservice call and noticed that I'm getting a response back in Wireshark that says:

Code:
Server: Microsoft-IIS/6.0

[URL unfurl="true"]WWW-Authenticate:[/URL] NTLM

X-Powered-By: ASP.NET

MicrosoftSharePointTeamServices: 12.0.0.4518

Date: Mon, 27 Dec 2010 21:32:40 GMT



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]

<HTML><HEAD><TITLE>You are not authorized to view this page</TITLE>

<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">

<STYLE type="text/css">

  BODY { font: 8pt/12pt verdana }

  H1 { font: 13pt/15pt verdana }

  H2 { font: 8pt/12pt verdana }

  A:link { color: red }

  A:visited { color: maroon }

</STYLE>

</HEAD><BODY><TABLE width=500 border=0 cellspacing=10><TR><TD>



<h1>You are not authorized to view this page</h1>

You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a [URL unfurl="true"]WWW-Authenticate[/URL] header field that the Web server is not configured to accept.

<hr>

<p>Please try the following:</p>

<ul>

<li>Contact the Web site administrator if you believe you should be able to view this directory or page.</li>

<li>Click the <a href="javascript:location.reload()">Refresh</a> button to try again with different credentials.</li>

</ul>

<h2>HTTP Error 401.2 - Unauthorized: Access is denied due to server configuration.<br>Internet Information Services (IIS)</h2>

<hr>

<p>Technical Information (for support personnel)</p>

<ul>

<li>Go to <a href="[URL unfurl="true"]http://go.microsoft.com/fwlink/?linkid=8180">Microsoft[/URL] Product Support Services</a> and perform a title search for the words <b>HTTP</b> and <b>401</b>.</li>

<li>Open <b>IIS Help</b>, which is accessible in IIS Manager (inetmgr),

 and search for topics titled <b>About Security</b>, <b>Authentication</b>, and <b>About Custom Error Messages</b>.</li>

</ul>

So my thought was that I am not running with the correct credentials. I next try and run VS as "administrator" (I just upgraded to Windows 7 and am having alot of security pains) but that didn't work.

So I then loaded up another program that I have that accesses a different sharepoint site a did the wireshark trace on that and it returns almost the exact same message in the "TCP Stream" of the wireshark info. Now my program gets a return from the sharepoint service as an exception, but the other program gets valid data.

Anyone have any ideas????
 
To add to the confusion, just calling the method "GetList" returns data successfully. That is using the same webservice, the same credentials, and just takes in the name of the list as a parameter.

My thought is it's either a problem in my xml for the parameters that are getting sent, or the permissions for the DATA of the specific list that I'm trying to retrieve from...would the permissions be different for retrieving the schema for a list, as opposed to the actual data that resides in that list?
 
I guess I'll update all of you.

I switched from using an xml file containing all of the CAML stuff and just created an xml document inside the code and it started working. Something was wrong with how I created my xml document (as an actual file), but I don't know what. Can I give myself a star?

There are MANY sites that show how to do it the way I got it to work, but here's one of them:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top