Tuesday 19 March 2013

Web Method of custom SharePoint 2007 web services not getting update


Web Method of custom SharePoint 2007 web services not getting update

I created custom web services for SharePoint 2007 which I am going to consume in K2 2003 Server work flow. I added a new web method to custom web services (How to create custom web services) and then to make it work in my SharePoint 2007 environment I followed following steps,


  • Created a new virtual directory for web services in IIS Manager web services application with application pool that has been used for services.
  • When you are updating or adding something new to your web services solution, you will have to delete bin folder of the solution and re-compile solution in both debug and release mode or as required.

  • Point virtual directory to your web services solution, mine is on desktop as I am developing and debugging instead of developing, building and then putting files in virtual directory and I think most developers do same.
  • Run disco Commands in Visual Studio 2008 Command Prompt e.g.

    C:\Program Files\Microsoft Visual Studio 9.0\VC>disco http://localhost:99999/mySharePointLists2.asmx
  • Above command will get you two files in same folder directory as above.

In both files, replace the XML instruction:


<?xml version="1.0" encoding="utf-8"?>



With



<%@ Page Language="C#" Inherits="System.Web.UI.Page" %>

<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Import Namespace="Microsoft.SharePoint.Utilities" %>

<%@ Import Namespace="Microsoft.SharePoint" %>

<% Response.ContentType = "text/xml"; %>


In the .disco file, replace the <contractRef> tag with one using virtualised URLs:



<contractRef ref="http://localhost/web/customWebservice.asmx?wsdl" docRef="http://localhost/web/customWebservice.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" />



With



<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + "?wsdl"),Response.ContentType = "text/xml"; %>
And update the <soap address> tags to use virtualised URLs and the correct method bindings and XML namespace:



<soap address="http://localhost/web/customWebservice.asmx" xmlns:q1="http://dev.com/" binding="q1:CustomWebserviceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

<soap address="http://localhost/web/customWebservice.asmx" xmlns:q2="http://dev.com/" binding="q2:CustomWebserviceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />



With



<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>

xmlns:q1="http://tempuri.org" binding="q1:CustomWebserviceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>

xmlns:q2="http://tempuri.org" binding="q2:CustomWebserviceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />




In the .wsdl file, replace the <soap address> tags with virtualised versions:



<wsdl:service name="CustomWebservice">

<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Web Service Description here...</wsdl:documentation>

<wsdl:port name="CustomWebserviceSoap" binding="tns:CustomWebserviceSoap">

<soap:address location="http://localhost/web/customWebservice.asmx" />

</wsdl:port>

<wsdl:port name="CustomWebserviceSoap12" binding="tns:CustomWebserviceSoap12">

<soap12:address location="http://localhost/web/customWebservice.asmx" />

</wsdl:port>

</wsdl:service>



With



<wsdl:service name="CustomWebservice">

<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Web Service Description here...</wsdl:documentation>

<wsdl:port name="CustomWebserviceSoap" binding="tns:CustomWebserviceSoap">

<soap:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />

</wsdl:port>

<wsdl:port name="CustomWebserviceSoap12" binding="tns:CustomWebserviceSoap12">

<soap12:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />

</wsdl:port>

</wsdl:service>


Rename the two files to have an .aspx extension, e.g. customWebservicedisco.aspx and customWebservicewsdl.aspx
Deploy the .asmx, disco and wsdl files to 12\ISAPI. Check the NTLM permissions!
Deploy the DLL to the GAC and to the web applications /bin directory (check the NTLM permissions again). DO NOT know why both are necessary… Probably a CAS thing, you could probably get the same result by installing to the \bin directory only and raising the trust level on the server to full; or by creating a custom CAS policy
Reset IIS
Should be able to access the web service at http://portalsite.com/_vti_bin/webservice.asmx

No comments:

Post a Comment