Thursday, July 16, 2009

Working with the BDC

I'm back to doing some BDC work and now remember how much I disliked it. I'm using hte BDC Application Definition Designer that comes with the SDK but it's always helpful to have a little refresher course on what everything does.

Randy Williams wrote and 8 part series over at that you should check out.

Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, Part 7, Part 8

Tuesday, July 7, 2009

Creating custom SharePoint web services

I found there are a lot of instructions on how to create web services but not many that give a best practices approach to doing this inside your solution in a way that is easy to repeat (like when you create new web methods in your custom web service and you don't want to manually re-edit all the wsdl and disco junk).

First, you need to download two things to follow along:

  2. WSS Web Service Helper

Next, follow these steps:

  1. Create a new project in STSDEV, use the empty project C# assembly
  2. Add a new Web Service Application Project to your solution
  3. Add your web method to your web service. (If you just want to test this out, the default HelloWorld will work)
  4. Run the WSS Web Service Helper against your .asmx file (in your web service project). This will autogenerate your wsdl and disco .aspx files.
  5. Copy the .asmx file and the .cs codebehind (your webservice) and the two .aspx files generated by the WSS Web Service Helper and place them into your Rootfiles/ISAPI folder in your STSDev project.
  6. Go to your .asmx file and delete the CodeBehind attribute of the Webservice tag and place the fully qualified assembly string into the Class attribute (Namespace.Class, Assembly, Version, Culture, PublicKey)
  7. Go into the Generated *disco.aspx file and for both of the soap tags replace the address attribute with <% SPEncode.WriteHtmlEncodeWithQuote(Response,SPWeb.OriginalBaseUrl(Request), '"'); %>
  8. Next go to the *wsdl.aspx file and (at the bottom of the file) replace the location attribute of the soap12:address tag with <% SPEncode.WriteHtmlEncodeWithQuote(Response,SPWeb.OriginalBaseUrl(Request), '"'); %>
  9. Also in both the *disco.aspx and *wsdl.aspx files you need to change the <@ assembly tag to this:
    <%@ Assembly Name="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

    because the .disco generator puts the wrong version and adds an extra Microsoft.SharePoint to the assembly reference.
  10. Deploy your project and test.
  11. Finally, if you have trouble, go here for troubleshooting, the tips are at the bottom of the article.
When you need to add or update your web methods, do it in the Web Service project and then repeat steps 4-9. Hopefully this method makes it a little less painful for you to develop custom web services in SharePoint.