Archive for the ‘Visual Studio 2010’ Category

One I’ve been meaning to blog for a while, but just never got round to it Surprised smile

I came across an error when Creating a Custom web service for SharePoint when trying to deploy the web service to the ISAPI  folder, allowing me to access a web service through the  _vti_bin of SharePoint. 

When you create a web service and deploy it to a mapped folder the code behind, as expected goes into the GAC. However, there is no WSDL or DISCO file associated with the web service, so it doesn’t work. 

To create a web service which deploys to the _vti_bin

  1. Add a text file to the {SharePointRoot}\ISAPI mapped folder of your SharePoint project.
  2. Rename your text file to <ServiceName>.asmx. Now you have the service you now need to associate it to the code behind.
  3. Create a class and name it <ServiceName>.cs or .vb if you are that way inclined !!
  4. Add the following attributes to your class
       [WebService(Namespace = "/sharepoint/services/")]’>http://<yourdomain>/sharepoint/services/")]
       [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
       [System.ComponentModel.ToolboxItem(false)]
  5. Next, return to your asmx file created in step 2 and add the following to the top of the file
    <%@ WebService Language="C#" Class="<NameSpaceOfAssembly>.<NameOfServiceClass>, <NameSpaceOfAssembly>, Version=<VersionOfYourAssembly>, Culture=neutral, PublicKeyToken=<PublicKeyOfYourAssembly>" %>
    Note: If you don’t know the public key, build your project, open a Visual Studio command prompt and naviate to your debug folder. Then run the command sn –T <NameOfYourDll>.dll
  6. Next, you need to deploy your solution to get the asmx file into the ISAPI folder and your class into the GAC.
  7. Once deployed, navigate to the web service at <SharePointSite>_vti_bin/<PathIfAny>/<ServiceName>.asmx and you should see your service with any web method you have added.
  8. Next, you will need to create WSDL and DISCO files to allow your to add reference to the service from a project.
  9. For some reason you don’t seem to be able to do this from the ISAPI folder, you receive a file not found error seen below. image
    So,  you need to copy the deployed file from the ISAPI folder to the LAYOUTS folder.
    Then run the command from the Visual Studio command prompt, ran as Administrator

    VisualStudioCommandPrompt

    disco
    /_layouts/.asmx">http://<SiteCollectionUrl>/_layouts/<NameOfService>.asmx 

  10. Once you have successfully ran this for the instructions in the “Generating and Modifying Static Discovery and WSDL Files” section of the Creating a Custom ASP.NET Web Service page on MSDN. 
  11. Copy these newly create wsdl and disco files back into your project and redeploy.

Please note: This tedious process will have to be redone anytime you add a new web method to your service.

Quick one, more for memory than anything:

Recently, I’ve been having a problems when trying to debug SharePoint projects – the debug symbols could take up to 20 minutes to load !!

Turns out there was quite a simple solution:

Delete all the breakpoints and only add in the ones you actually need.

This probably won’t ever be a problem for most of you out there, but after working on the same solution for 6 months the breakpoints have gradually built up. 

Rather than building something which had to be deployed to SharePoint which was of no use to the application. I decided it would be easier to just, quickly, build a console application to get some values and write them to a file. This was the way I had done it before using MOSS. However, when I did this on the Sharepoint 2010, it complained with FileNotFoundException. image As can be seen in the image below.

This puzzled me at first, but after some digging I found that not only do you have to change the .NET Framework imageversion to 3.5, but you also have to set the platform target to x64.  This is done from the build tab of the project properties.

Once you know, it makes sense, but at first it caused a little confusion!

In debug mode, you can hover over an item and drill down through its properties using the ‘+’ button.

In VS2010, if you look at the right hand side you’ll find a pin which can be used to pin a particular field to that line of code.

This can be done on several lines of code so you can see what the values of fields are as you move through the code. A pin appears in the left hand margin.

debug-pinning

After the debug is finished, if you hover over the pin it shows you the last value held in that field during the debug session.

After installing Re-Sharper 5.0 I then installed Style cop for Re-Sharper to allow my code to comply with MS Style Cop and give me real-time syntax highlighting of violations.  However, after installation, when I opened Visual Studio I received the following error.

resharper for style cop coule not be loaded

This is because the  dll has not been given full trust. To resolve this issue follow the instructions of how to Use an Assembly from the Web in Visual Studio.