Sharepoint: publish a webservice with your solution

In this article I’ll cover how can you publish a WebService with your solution that will be accessible at every site in all the web applications where the solution is deployed. To keep thing simple, I’ve chosen a simple Helloworld webservice but with this approach we could publish any webservice or .aspx pages or a httpHandler

What we will do is to publish the service in the _vti_bin sharepoint folder of our site. To do this, we must first copy the .asmx file of the service in the Common FilesMicrosoft Sharedweb server extensions12ISAPI folder of our server.

<%@ WebService Language=”c#” Class=”MyAssembly.Services.HelloWorldService,MyAssembly.Services”%>

This was the .asmx file we want to distribute and following is the .DDF file from which we’ll generate the solution, I’d like to show that you could also publish a web.config file for the _vti_bin/MyAssembly folder, we would want to do so if, for example, were deploying an httpHandler instead of a webservice or if we need to configure some AppSettings parameters.

; Solution.DDF
FeaturesISAPIMyAssemblyweb.config ISAPIMyAssemblyweb.config
FeaturesISAPIMyAssemblyHerramientas.asmx ISAPIMyAssemblyHelloWorldService.asmx
ServicesbinDebugMyAssembly.Services.dll MyAssembly.Services.dll

Then we must define the manifest.xml file used in the solution deployment:

<RootFile Location=ISAPIMyAssemblyweb.config />
< RootFile Location=ISAPIMyAssemblyHelloWorldService.asmx />

<Assemblies><Assembly DeploymentTarget=WebApplication Location=MyAssembly.Services.dll /></Assemblies>

Remember to set the appropiate assembly permission at the CodeAccessSecurity section of the manifest.xml file if not running under Full Trust mode or not deploying the assembly in the GAC.

Finally, here is the easy code of our Helloworld service:

namespace MyAssembly.Services
    [WebService(Namespace = "")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class HelloWorldService : System.Web.Services.WebService

        public string HelloWorld()
            return "Greetings from this Service !";


Now, after deploying the solution we can access the webservice adding _vti_bin/MyAssembly/HelloWorldService.asmx at our site url (for those sites we have deployed the solution to !). However, If we have deployed the solution in the GAC, the service should be able to all the sites in the server.

That’s all for now ! As always, feel free to comment anything you might find interesting !


8 Responses to Sharepoint: publish a webservice with your solution

  1. Paul Celi says:


    Very nice, I was looking for this !

    I managed to create the solution and deploy everything like you described in this article.

    But When I try to access my webservice I get this error:

    The document at the url http://localhost/_vti_bin/SiemensDocumentWebServices.asmx was not recognized as a known document type.
    The error message from each known type may help you fix the problem:
    – Report from ‘DISCO Document’ is ‘There was an error downloading ‘http://localhost/_vti_bin/SiemensDocumentWebServices.asmx?disco’.’.
    – The request failed with the error message:

    Object moved
    Object moved to here.

    – Report from ‘http://localhost/_vti_bin/SiemensDocumentWebServices.asmx’ is ‘The document format is not recognized (the content type is ‘text/html; charset=utf-8′).’.
    – Report from ‘WSDL Document’ is ‘The document format is not recognized (the content type is ‘text/html; charset=utf-8′).’.
    – Report from ‘XML Schema’ is ‘The document format is not recognized (the content type is ‘text/html; charset=utf-8′).’.

    I think we miss the disco step (hihi) which is needed to create the .disco and .wsdl file..

    How would you include this in the deployement procedure? do the disco.exe and copy the files using the manifest.xml


  2. oricode says:

    You are right. For some procedures like, for example, adding the web service as a reference in a visual studio project, the discovery (.disco) and wsdl files are required.

    I suggest you to use a tool called WSSWebServicePackager which will assist you in generating those files for a service. Just one note when using this tool, you’ll have to deploy the service in another folder other than ISAPI\ , just place it temporary in the LAYOUTS\ folder and it will work fine ! This tool will create both files and then you just have to copy them in the ISAPI\ folder where your .asmx files are located.

  3. Paul Celi says:

    Thks for the quick response!

    How could I do those steps of disco(ing) the asmx to the Layouts\ then copy the files generated to ISAPI\ part of the solution deployement?

  4. oricode says:

    Here is what you should do:

    1. Copy the .asmx file from the ISAPI\ folder to the TEMPLATE\LAYOUTS\ folder
    2. Start WSSWebServicePackager tool
    3. On the url input box write the url: http://sp_server/_layouts/service_name.asmx
    4. Generate the files (after specifying an output folder)
    5. Copy the generated files (.disco and .wsdl) in the ISAPI\ folder

    After that, you should be able to access the web service normally. Also, I’d recommend you to add those generated files in the .wsp solution in case you are using one for an easier deployment.

    Hope it helps ! thx for your comments

  5. Paul Celi says:

    Well I finally managed to make it work but it’s a bit the problem of the “Chiken and the egg”. You need the asmx deployed on the server to generate the disco and wsdl files that you need to add to the wsp.
    So I deploy two times. Once to add the asmx to the Layouts\ then once I got my disco and wsdl redeploy in ISAPI\

    (and don’t forget to rename the file.disco that is generated in filedisco.apsx before adding to ISAPI)

    Thanks again !

  6. Matt Morse says:

    Hi Oriol,

    Thanks for the post; you definitely got me on the right track. Just a note that the WSSWebServicePackager tool adds assembly references and does file replacements for WSS 2.0/SPS. You need to update the assembly reference and the SOAP 1.2 references manually in the *disco.aspx and *wsdl.aspx that the tool generates. I’m thinking about updating their code and submitting it back, but until I get to that, this might help someone else. 🙂


  7. Matt Morse says:

    Oops, the comment above should say that you need to update the assembly reference and other tags if you’re using WSS 3.0/MOSS. Hit “Submit” too soon.

  8. Mark Wagner says:

    Nice posting oricode. This is information every SharePoint developer should know and understand – but creating the disco.aspx and wsdl.aspx files can quickly become tedious. I created a tool to generate the SharePoint disco.aspx and wsdl.aspx web service files automatically with one command. No disco.exe needed. I ask that you check it out. Here is the url.

    Thanks oricode,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: