SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to web services and i've been trying to create a custom one using this tutorial:

I've named my service as Files and created a new method on the webservice called UploadDocument:

    public string UploadDocument(string fileName, byte[] fileContents, string pathFolder)
        if (fileContents == null)
            return "Null Attachment";

            int iStartIndex = pathFolder.LastIndexOf("/");
            string sitePath = pathFolder.Remove(iStartIndex);
            string folderName = pathFolder.Substring(iStartIndex + 1);

            SPSite site = new SPSite(sitePath);
            SPWeb web = site.OpenWeb();

            SPFolder folder = web.GetFolder(folderName);

            string fileURL = fileName;

            folder.Files.Add(fileURL, fileContents);

            if (folder.Files[fileURL].CheckedOutByUser.Name != "")
                folder.Files[fileURL].CheckIn("File Checked In");

            return "File added successfully!";

        catch (System.Exception ex)
            return "Error: " + ex.Source + " - " + ex.Message;

I've done exactly as it's listed there, all the same name, methods etc.. and when i get to the point where you're asked to create the application that's going to consume the web service, the tutorial gives the following lines:

ServiceFolder.Files myUploadService = new ServiceFolder.Files();
myUploadService .UseDefaultCredentials = true;

but on my application, i can't call the web service as it's telling me to do, when i type


it won't have the option to call the classes i've created. it only gives me some options that are not the ones listed on the tutorial:

ServiceFolder.FilesSoap (Interface)
ServiceFolder.FilesSoapChannel (Interface)
ServiceFolder.FilesSoapClient (Class)
ServiceFolder.UploadDocumentCompletedEventArgs (Class)
ServiceFolder.UploadDocumentRequest (Class)
ServiceFolder.UploadDocumentRequestBody (Class)
ServiceFolder.UploadDocumentResponse (Class)
ServiceFolder.UploadDocumentResponseBody (Class)

Am i missing something? doing something wrong? i've tried to recreate the service a couple times and always get the same thing.

Thanks in advance.

share|improve this question
up vote 12 down vote accepted

That walkthrough has some, er, issues...

I wrote a blog post with an alternate version that you may find a little easier to follow.

Walkthrough: Creating a Custom ASP.NET (ASMX) Web Service in SharePoint 2010

share|improve this answer
Rob.. i don't have words to express how grateful i am for this walkthrough. Just one little question. How do you invoke the GetSiteListCount() method in your site/application? I've added the service reference, but i can't find how to call that method and use it's result on my code. Thanks a lot – C. Hoffmann Nov 7 '11 at 13:39
I've updated the blog post to demonstrate how to create a client for the service. – Rob Windsor Nov 7 '11 at 14:42
Rob. It worked like a charm. Thank so you much for your help. – C. Hoffmann Nov 7 '11 at 16:24
Thanks @RobWindsor, I was looking for similar solution. – Nikhil Chavan Jun 8 '15 at 10:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.