401: Access Denied when calling a web service


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: 401: Access Denied when calling a web service

  1. #1
    salthead Guest

    401: Access Denied when calling a web service


    I have created a web service to retrieve data. I can run this service by
    typing in the URL. But when I try to run it programatically, I get the access
    Denied error. I have added it as reference in my calling program. What
    else am I missing?

    Calling code below:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Handles MyBase.Load
    'Put user code to initialize the page here

    End Sub
    Private Sub BindData()
    Dim ds As DataSet

    ' Must add Web Reference in solution explorer R Click on References
    | Add Web Reference
    Dim objData As New localhost.clsDataService()

    ds = objData.QueryData("nwind", txtTextBox.Text)

    DataGrid1.DataSource = ds

    DataBind()

    objData = Nothing
    End Sub



    Web Service Below:

    <WebMethod()> Public Function QueryData(ByVal strapplication As String,
    _
    ByVal strSql As String) As DataSet

    Dim strConn As String
    Dim objConn As OleDbConnection
    Dim objDa As OleDbDataAdapter

    Dim objDS As New DataSet()

    Select Case UCase(strapplication)
    Case "NWIND"
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\program files\microsoft office\office\samples\northwind.MDB;"
    Case "PUBS"
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\program files\microsoft office\office\samples\Pubs.MDB;"
    End Select

    'Identify select statement
    'opening the connection
    objConn = New OleDbConnection(strConn)
    objDa = New OleDbDataAdapter(strSql, objConn)

    'getting the data Set
    objDa.Fill(objDS, "objTable")
    Return objDS

    objConn.Close()
    objConn = Nothing
    objDa = Nothing

    End Function


  2. #2
    salthead Guest

    Re: 401: Access Denied when calling a web service


    Just figured it out. There was nothing wrong with the code. The problem
    was on the IIS. Annonymous Access was turned off. I turned it on and everything
    works fine.


    "salthead" <salthead@abs.com> wrote:
    >
    >I have created a web service to retrieve data. I can run this service by
    >typing in the URL. But when I try to run it programatically, I get the

    access
    >Denied error. I have added it as reference in my calling program. What
    >else am I missing?
    >
    >Calling code below:
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    >Handles MyBase.Load
    > 'Put user code to initialize the page here
    >
    > End Sub
    > Private Sub BindData()
    > Dim ds As DataSet
    >
    > ' Must add Web Reference in solution explorer R Click on References
    >| Add Web Reference
    > Dim objData As New localhost.clsDataService()
    >
    > ds = objData.QueryData("nwind", txtTextBox.Text)
    >
    > DataGrid1.DataSource = ds
    >
    > DataBind()
    >
    > objData = Nothing
    > End Sub
    >
    >
    >
    >Web Service Below:
    >
    > <WebMethod()> Public Function QueryData(ByVal strapplication As String,
    >_
    > ByVal strSql As String) As DataSet
    >
    > Dim strConn As String
    > Dim objConn As OleDbConnection
    > Dim objDa As OleDbDataAdapter
    >
    > Dim objDS As New DataSet()
    >
    > Select Case UCase(strapplication)
    > Case "NWIND"
    > strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    > "Data Source=c:\program files\microsoft office\office\samples\northwind.MDB;"
    > Case "PUBS"
    > strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    > "Data Source=c:\program files\microsoft office\office\samples\Pubs.MDB;"
    > End Select
    >
    > 'Identify select statement
    > 'opening the connection
    > objConn = New OleDbConnection(strConn)
    > objDa = New OleDbDataAdapter(strSql, objConn)
    >
    > 'getting the data Set
    > objDa.Fill(objDS, "objTable")
    > Return objDS
    >
    > objConn.Close()
    > objConn = Nothing
    > objDa = Nothing
    >
    > End Function
    >



  3. #3
    Yann Christensen Guest

    Re: 401: Access Denied when calling a web service

    Note, the reason it worked in IE is that IE will automatically do an NTLM
    negotiation with your domain credentials. You can enable the same type of
    authentication for your web service client by adding this code:

    objData.Credentials = System.Net.CredentialCache.DefaultCredentials


    Here is the relevant help page:
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemnetcredentialcacheclassdef
    aultcredentialstopic.htm

    -Yann

    "salthead" <salthead@abs.com> wrote in message news:3d3c4d5d$1@10.1.10.29...
    >
    > Just figured it out. There was nothing wrong with the code. The problem
    > was on the IIS. Annonymous Access was turned off. I turned it on and

    everything
    > works fine.
    >
    >
    > "salthead" <salthead@abs.com> wrote:
    > >
    > >I have created a web service to retrieve data. I can run this service by
    > >typing in the URL. But when I try to run it programatically, I get the

    > access
    > >Denied error. I have added it as reference in my calling program. What
    > >else am I missing?
    > >
    > >Calling code below:
    > >
    > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As

    System.EventArgs)
    > >Handles MyBase.Load
    > > 'Put user code to initialize the page here
    > >
    > > End Sub
    > > Private Sub BindData()
    > > Dim ds As DataSet
    > >
    > > ' Must add Web Reference in solution explorer R Click on

    References
    > >| Add Web Reference
    > > Dim objData As New localhost.clsDataService()
    > >
    > > ds = objData.QueryData("nwind", txtTextBox.Text)
    > >
    > > DataGrid1.DataSource = ds
    > >
    > > DataBind()
    > >
    > > objData = Nothing
    > > End Sub
    > >
    > >
    > >
    > >Web Service Below:
    > >
    > > <WebMethod()> Public Function QueryData(ByVal strapplication As

    String,
    > >_
    > > ByVal strSql As String) As DataSet
    > >
    > > Dim strConn As String
    > > Dim objConn As OleDbConnection
    > > Dim objDa As OleDbDataAdapter
    > >
    > > Dim objDS As New DataSet()
    > >
    > > Select Case UCase(strapplication)
    > > Case "NWIND"
    > > strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    > > "Data Source=c:\program files\microsoft

    office\office\samples\northwind.MDB;"
    > > Case "PUBS"
    > > strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    > > "Data Source=c:\program files\microsoft

    office\office\samples\Pubs.MDB;"
    > > End Select
    > >
    > > 'Identify select statement
    > > 'opening the connection
    > > objConn = New OleDbConnection(strConn)
    > > objDa = New OleDbDataAdapter(strSql, objConn)
    > >
    > > 'getting the data Set
    > > objDa.Fill(objDS, "objTable")
    > > Return objDS
    > >
    > > objConn.Close()
    > > objConn = Nothing
    > > objDa = Nothing
    > >
    > > End Function
    > >

    >




  4. #4
    d Guest

    Re: 401: Access Denied when calling a web service


    Yann Christensen : YOU ROCK!!
    mine webserv works like a charm now.!
    thank u

  5. #5
    Join Date
    Jul 2009
    Posts
    10
    If you are using webservice

    and anonymous authentication is turned off

    follow the the steps

    http://sysisundefined.blogspot.com/2...pnet-cnet.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center