Sunday, August 7, 2011

Sharepoint 2010 bug: incorrect wsdl of TaxonomyClientService.asmx web service

Recently I found interesting problem when work with TaxonomyClientService.asmx. This service can be used by client applications in order to work with Sharepoint managed metadata. As msdn says:

This Web service enables a client to interact with the managed metadata TermStore object and get the data through label matching, per Microsoft.SharePoint.Taxonomy.TermSet, or by GUID. Updates to the TermStore can also be made by adding a new Term object.

As many other OTB Sharepoint web services, TaxonomyClientService.asmx file is located in 14/ISAPI folder and is accessible by the following URL: http://example.com/_vti_bin/TaxonomyClientService.asmx (where http://example.com part belongs to some Sharepoint web site). When you enter this URL you will see the following web methods:

image

  • AddTerms
  • GetChildTermsInTerm
  • GetChildTermsInTermSet
  • GetKeywordTermsByGuids
  • GetTermSets
  • GetTermsByLabel

In order to use this web service we should perform usual steps: add service reference (or web reference) and use generated proxy. And here we got the problem: in generated proxy class all web methods exist except GetChildTermsInTerm and GetChildTermsInTermSet:

image

This was strange. The first thing I made is checked TaxonomyClientService class in Reflector to ensure that mentioned methods contains [WebMethod] attribute. They had it:

image

Then I checked wsdl of the TaxonomyClientService.asmx (added ?wsdl to the web service url) – and it didn’t contain the definition of the GetChildTermsInTerm and GetChildTermsInTermSet methods. So that was the problem.

As you probably know in Sharepoint wsd land disco files are located near asmx file in format *wsdl.aspx and *disco.aspx. So I checked TaxonomyClientServicewsdl.aspx – and, as I expected, definitions of GetChildTermsInTerm and GetChildTermsInTermSet methods were missing here. For me this looks like a bug.

Visual Studio uses these *wsdl.aspx files in order to generate web service proxy. Also IE uses it when you click on Service Description link on the web service page. Try to rename TaxonomyClientServicewsdl.aspx to TaxonomyClientServicewsdl.aspx_ (with leading underscore) and you will see that neither VS nor IE can show wsdl anymore. Rename it back and they will work again.

Ok, we know the reason, but what we should do before we will get official patch from MS? We need to fix it by ourselves. That’s how you can do it:

  1. Backup original wsdl file TaxonomyClientServicewsdl.aspx to TaxonomyClientServicewsdl.aspx_orig
  2. Copy TaxonomyClientService.asmx to 14/Template/Layouts/Test (but don’t copy *wsdl.aspx and *disco.aspx files). Doing by this you will get wsdl file generated dynamically based on actual asmx web methods.
  3. Use disco.exe tool from MS SDK in order to generate the correct wsdl of the web service using the new URL (or just open the following URL in browser http://example.com/_layouts/test/TaxonomyClientService.asmx?asmx):

    disco.exe http://example.com/_layouts/test/TaxonomyClientService.asmx
  4. It will generate 2 files: TaxonomyClientService.disco and TaxonomyClientService.wsdl
  5. Check that newly generated wsdl file contains definitions of GetChildTermsInTerm and GetChildTermsInTermSet methods
  6. Now we need compare original TaxonomyClientServicewsdl.aspx and generated TaxonomyClientService.wsdl file and copy missing parts from newly generated file into original file. Note, that you should not just replace original file with new one because it has additional code for adopting it for Sharepoint (Page directive and SPEncode.WriteHtmlEncodeWithQuote()). I used Beyond compare tool and just copy parts of code from wsdl file to TaxonomyClientServicewsdl.aspx which are related with missing methods.

After you will save changes in TaxonomyClientServicewsdl.aspx you should update reference in your VS project – and after that you will be able to use GetChildTermsInTerm and GetChildTermsInTermSet methods in the code:

image

I uploaded fixed version of TaxonomyClientServicewsdl.aspx file here.

Recently SP1 was released for Sharepoint 2010 however I don’t have it now to check whether or not this bug was fixed there. Will update this post as far as I will check it.

8 comments:

  1. I have SP1, and those definitions exist.

    ReplyDelete
  2. Thank you! You've saved my brain!

    ReplyDelete
  3. Hi, Alex. If I understand correctly, in SP1 this issue still doesn't fixed, does it?. I've done the same actions, and got the identical TaxonomyClientServicewsdl.aspx file. After that GetChildTermsInTermSet method works well, but GetChildTermsInTerm method does not. It always throws exception like "Server was unable to process request. ---> Object reference not set to an instance of an object." Have you ever tried to use this method?

    ReplyDelete
  4. Sergey,
    I didn't check it in SP1 by myself - may be it still exists (Nuno commented above that it still exists). This problem was investigated for my colleague - he said that it worked.

    ReplyDelete
  5. I know this is an older post, but I am now having this issue. I have updated the wsdl file, but still not seeing the GetChildTerms... Do I have to update the TaxonomyClientService.asmx or a .dll too? I think I am missing something obvious, but not sure what.

    ReplyDelete
  6. Craig,
    as far as I remember neither asmx nor dll should be updated. Try to create new project in VS and add new service reference there. May be there is something wrong with updating service reference in VS.

    ReplyDelete
  7. Well apparently you have to update the web server, not the application server. It works a lot better once you do the right thing. :)

    Thanks!!!

    Craig

    ReplyDelete