More in this section

Forums / Developing with Sitefinity / Pass authentication to web service

Pass authentication to web service

3 posts, 0 answered
  1. J
    J avatar
    1 posts
    Registered:
    14 Feb 2008
    14 Feb 2008
    Link to this post
    I plan to use SF to set up a few websites that have restricted areas that require users to log in.  So far, I got this working without much effort!

    Now I need to call a web service that will return some content to display in SF.  The web service needs to verify that the user/site that requested the content has permission to view it.

    This leaves me with the following questions:
    1. How can I display content provided by a web service within SF?
    2. Is there any way to pass a token from within SF that an outside service can validate?


    Thank you,
    John
  2. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    14 Feb 2008
    Link to this post

    We built an example of this for an older version of Sitefinity. I think 3.0. We used the RadAjax client side functionality to call the webservices. However, keep in mind that if you want to call across a domain you will have to call your web service from the codebehind.

    In this example we call the webservice alightenWebSiteDetails.asmx on the page load.

    The UserControl:

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="Copy of alightenWebSiteDetails.ascx.vb" Inherits="UserControls_services_alightenWebSiteDetails" %> 
    <%@ Register Assembly="RadAjax.Net2" Namespace="Telerik.WebControls" TagPrefix="radA" %> 
    <radA:RadAjaxServiceManager ID="RadAjaxServiceManager1" runat="server">  
        <WebServices> 
            <radA:WebServiceReference Path="~/UserControls/services/alightenWebSiteDetails.asmx" /> 
        </WebServices> 
    </radA:RadAjaxServiceManager> 
    <script type="text/javascript">  
    function getRecentlyChangedPages() {   
        ret = alightenWebSiteDetails.GetRecentlyChangedPages(5, recentlyChangedPagesResponse, ServiceErrorCallback);  
    }   
    function recentlyChangedPagesResponse(ResponseAsJSON, ResponseAsXml, ResponseAsText) {   
     
         var parser = new RadAjaxServiceNamespace.ServiceResponseParser();  
                            
         var myListHTML = "<ul>";  
           
         for(var i = 0; i < ResponseAsJSON.Page.length ; i++)  
         {  
          
         var pageItem = ResponseAsJSON.Page[i];  
         var listItem = "<li>" + pageItem.Name + "</li>";  
         myListHTML += listItem;  
         }  
                              
         myListHTML += "</ul>";  
     
         $(recentlychangedPages).setHTML(myListHTML);  
    }   
    function ServiceErrorCallback(args) {   
        alert(args.ErrorText);   
    }  
    window.addEvent('load', getRecentlyChangedPages);  
    </script>  

    And the Webservice .vb file (in the App_Code):

    Imports System.Data  
    Imports System.Web  
    Imports System.Web.Services  
    Imports System.Web.Services.Protocols  
     
    Imports Telerik.Cms  
    Imports Telerik.Cms.Web  
     
     
    <WebService(Namespace:="http://tempuri.org/")> _  
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _  
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _  
    Public Class alightenWebSiteDetails  
         Inherits System.Web.Services.WebService  
     
        <WebMethod()> _  
        Public Function GetRecentlyChangedPages(ByVal qty As IntegerAs DataSet  
            Try 
                Dim i As Integer = 0  
                Dim dsPages As New DataSet  
                Dim dtPages As DataTable = dsPages.Tables.Add("Page")  
     
     
                Dim cms As New CmsManager  
                Dim pageList As IList  
     
                pageList = cms.GetPages  
     
     
                dtPages.Columns.Add("URL")  
                dtPages.Columns.Add("Name")  
                dtPages.Columns.Add("DateModified")  
     
                For i = 0 To qty - 1  
     
                    Dim page As ICmsPage  
                    page = pageList(i)  
                    Dim rowPage As DataRow = dtPages.NewRow()  
     
                    rowPage("URL") = page.StaticUrl  
                    rowPage("Name") = page.MenuName  
                    rowPage("DateModified") = page.DateModified  
                    dtPages.Rows.Add(rowPage)  
     
                Next 
     
                Return dsPages  
            Catch ex As Exception  
                Return Nothing 
            End Try 
        End Function 
     
        Public Function SortList(ByVal list As IList) As IList  
     
            Dim comparer As New PageComparer  
     
            CType(list, ArrayList).Sort(comparer)  
     
            Return list  
        End Function 
    End Class 
     
    Public Class PageComparer  
        Implements System.Collections.IComparer  
     
        Public Sub New()  
        End Sub 
     
        Public Function Compare(ByVal x As ObjectByVal y As ObjectAs Integer Implements System.Collections.IComparer.Compare  
            Dim page1 As Telerik.Cms.IPage = DirectCast(x, Telerik.Cms.IPage)  
            Dim page2 As Telerik.Cms.IPage = DirectCast(y, Telerik.Cms.IPage)  
     
            Return DateTime.Compare(page1.DateModified, page2.DateModified)  
     
        End Function 
    End Class 
     

    The Sitefinity API is probably quite a bit different now. But the setup should be the same.

    I hope this gives you a good starting point. Please let me know if you were looking for something else and I'll see if I can put together an updated example for you.

    Sincerely,

    Ben
  3. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    20 Feb 2008
    Link to this post
    The Telerik blogs announced this new webservice via proxy example posted in the Telerik code samples:

    http://www.telerik.com/community/code-library/submission/b311D-bcagkk.aspx

    Perhaps that can point you in the right direction for cross domain webservice calls.

    Sincerely,

    Ben
Register for webinar
3 posts, 0 answered