Welcome to InteropTips Sign in | Join | Help


Demos

Last post 05-23-2007, 3:35 PM by mikedu. 7 replies.
Sort Posts: Previous Next
  •  04-11-2006, 10:50 AM 25

    Calling a Domino 7 web service with security and identity

    This Window Form Project uses Joe Users credentials in calling a public Domino 7 web service. The security for this web service does not allow anonyms access. In the header of the request, Joe User’s User Name and Password is passed. Domino uses this information to authenticate Joe User. The Name parameter that is passed in is appended to a string containing the effective user.

     

     

    Dim DominoWS As New net.msdomino.www.helloService ' create Domino web service proxy object

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim Cred As New NetworkCredential(TextBox2.Text, TextBox3.Text) ' Set User Name/Password credentials

    Try

    DominoWS.Credentials = Cred ' asign credential to web service

    DominoWS.PreAuthenticate = True ' force credentials in first call

    TextBox4.Text = DominoWS.HELLO_NAME(TextBox1.Text) ' call call web service

    Catch ex As Exception

    TextBox4.Text = ("Error:" & ex.Source & vbCrLf & ex.Message) ' Report errors

    End Try

    End Sub

    For more security, use SSL along with this method

    As a bonus, Button "Agent Name" returns the name of the Web Agent that is acting as the web service. Our web service Name is "check_ID". Note if this button is used first, the credentials are not set and it will fail.

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    ' just for fun, this method returns the Agent name that is acting as the Web Service

    TextBox4.Text = DominoWS.AGENT_NAME

    End Sub

  •  08-18-2006, 10:14 PM 73 in reply to 25

    Re: Calling a Domino 7 web service with security and identity

    Hi Gary

    I am having issues with webservice authentication and session based login.  I downloaded your application  and it works perfect on my test server when basic auth is being used but failed when I enable session based.  I have read on Notes.net that even with session based enabled the server should accept basic, but that is not what I am seeing. Any insight?

     

    Thanks for you time.

    Steve

  •  01-24-2007, 11:45 AM 106 in reply to 25

    Re: Calling a Domino 7 web service with security and identity

    Hi,

    I also noticed that when session based authentication is on the webservice authentication doesn't seem work.

    Is this a known problem or is there a sollution to solve this issue.

     

    /Lars

  •  02-19-2007, 12:56 AM 108 in reply to 106

    Re: Calling a Domino 7 web service with security and identity

    Hi Lars

    It appears like I have this working. I add the following constructor and function to the reference.vb file that is created when you inport a wsdl to VS

     

     

            Public Sub New(ByVal securityCookie As String)
                MyBase.New()
                Me.Url = "http://myhost.com/web.nsf/webservice"
                _authCookieValue = securityCookie
            End Sub
    
            Protected Overrides Function GetWebRequest(ByVal Uri As Uri) As System.Net.WebRequest
                Dim request As System.Net.WebRequest
                request = MyBase.GetWebRequest(Uri)
                request.Headers.Add("Cookie", "LtpaToken=" & _authCookieValue)
                Return request
            End Function
    
    

    securityCookie in the constructor is the LtpaToken of the user or admin depending on how you want to do it. If I am running as a user other than the current user, I have a function that I use to generate an admin LtpaToken.

        
    ''' <SUMMARY>
        ''' Generates a Notes Security Cookie for the specified user/password combo
        ''' </SUMMARY>
        ''' <PARAM name="loginUrl">The url to post to. (ex http://mycompany.com/names.nsf?Login)</PARAM>
        ''' <PARAM name="cookieName">The name of the returning cookine. (ex LtpaToken)</PARAM>
        ''' <PARAM name="userName">The username of the account to log in with</PARAM>
        ''' <PARAM name="password">The password of the account to log in with</PARAM>
        ''' <RETURNS type="System.Web.HttpCookie">The cookie generated with the login credentials</RETURNS>    
    Public Shared Function GenerateLtpaToken(ByVal loginUrl As String, ByVal cookieName As String, ByVal userName As String, ByVal password As String) As System.Web.HttpCookie
            'Put user code to initialize the page here
            Dim req As HttpWebRequest
            Dim res As System.Net.HttpWebResponse
            Dim sr As System.IO.StreamReader
            Dim cookieContainer As New System.Net.CookieContainer
            Dim securityToken As String
            Dim postDataByte As Byte()
            Dim postStream As Stream
            Dim retCode As Boolean = False
            Dim authorizationCookie As System.web.HttpCookie
    
            Try
                System.Net.ServicePointManager.Expect100Continue = False
    
                req = CType(WebRequest.Create(loginUrl), HttpWebRequest)
                req.CookieContainer = New CookieContainer
    
                'enncode the form data string into a byte array '
                postDataByte = System.Text.Encoding.ASCII.GetBytes("username=" & userName & "&password=" & password)
    
                'indicate that you will be posting the data 
                req.Method = "POST"
                req.ContentType = "application/x-www-form-urlencoded"
                req.ContentLength = postDataByte.Length
                req.AllowAutoRedirect = False
    
                'send the form 
                postStream = req.GetRequestStream()
                postStream.Write(postDataByte, 0, postDataByte.Length)
    
                ' Close the post
                postStream.Close()
    
                res = CType(req.GetResponse(), HttpWebResponse)
                res.Cookies = req.CookieContainer.GetCookies(req.RequestUri)
    
    
                'read in the page 
                'sr = New System.IO.StreamReader(res.GetResponseStream())
    
                ' Get the specified cookie
                If Not res.Cookies(cookieName) Is Nothing Then
                    '_AuthorizationCookie = CType(res.Cookies.Item(_authorizationCookieName), System.Web.HttpCookie)
                    Dim responseCookie As Cookie = res.Cookies.Item(cookieName)
                    Dim passThruCookie As New System.Web.HttpCookie(cookieName)
    
                    ' Convert the cookie to an httpCookie
                    passThruCookie.Domain = responseCookie.Domain
                    passThruCookie.Value = responseCookie.Value
                    passThruCookie.Expires = responseCookie.Expires
                    passThruCookie.Path = responseCookie.Path
    
                    authorizationCookie = passThruCookie
    
                End If
                Return authorizationCookie
            Catch ex As Exception
                Throw ex
            End Try
        End Function
    
  •  04-03-2007, 7:00 AM 119 in reply to 108

    Re: Calling a Domino 7 web service with security and identity

    I am trying to access from C#, when I added web reference, i couldnt find reference.cs file, so where I need to place this code.

    Is there any soultions to this.

     

  •  04-18-2007, 12:53 PM 121 in reply to 119

    Re: Calling a Domino 7 web service with security and identity

    Hi Jag

    In the Solution Explorer, look for the icon at the top that looks like three pieces of paper on top of each other, the hover should say "show all files". Click it, at that point your web reference should be expandable, expand it, then expand reference.map, and the reference file should be there. I posted an sample at http://www.openntf.org/projects/codebin/codebin.nsf/CodeByDate/F95837C5C37EC84D862572A800046428

    S

  •  05-15-2007, 12:58 AM 124 in reply to 25

    Re: Calling a Domino 7 web service with security and identity

    Hi Gary,
                I tried your application for calling the web service with security and identity .I placed your database in my server and i added my name in the ACL entry of the database and i passed the web reference with my WSDL location (http://testserver/joe_webservice.nsf/check_id?wsdl)but the .net code is returning the value as anonymous.

    Kindly suggest me what should be done



  •  05-23-2007, 3:35 PM 125 in reply to 124

    Re: Calling a Domino 7 web service with security and identity

    I am getting the same thing, Gary are you there?
View as RSS news feed in XML

Terms of Use |  Upload Agreement |  Trademarks |  Privacy Statement |  Contact Us

© 2006 Microsoft Corporation. All rights reserved.