Error calling web service

J

John

Hi

My first web service seems to be OK as I can put its url in explorer and can
use the invoke button to view the returned data as xml. The problem comes
when I call it form a client app using;

Dim ws As New localhost.StaffWS
Dim ds = ws.GetStaffDiary

When the second line above is executed I get a 'The request failed with HTTP
status 401: Access Denied.' error on the line indicated below in the
\webreferences\localhost\references.vb file on the line indicated below;

<System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost
/staff/staffws/StaffWS.asmx/GetStaffDiary",
RequestNamespace:="http://localhost/staff/staffws/StaffWS.asmx",
ResponseNamespace:="http://localhost/staff/staffws/StaffWS.asmx",
Use:=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Public Function GetStaffDiary() As System.Data.DataSet
Dim results() As Object = Me.Invoke("GetStaffDiary", New Object(-1) {})
'<== This line has the error.
Return CType(results(0),System.Data.DataSet)
End Function

Any idea what this error is about and how to fix it?

Thanks

Regards
 
S

Scott Allen

It looks as if the web service requires credentials to authenticate
the incoming request. From a client application you can pass
credentials along with the request:

ws.Credentials = System.Net.CredentialCache.DefaultCredentials;

DefaultCredentials will represent the credentials of the user running
the client process.

HTH,
 
S

S. Justin Gengo

John,

A followup note. Creating credentials really isn't too difficult but if you
want a component that will make it a bit easier I have one freely available
on my website, www.aboutfortunate.com. All the code on the site is free. And
all components are downloadable as Visual Studio.NET v1.1 projects. (So even
if you don't want to use the component as is you can at least use the code
as an example to follow.)

The component you'd be interested in is the Authentication component. Just
click the "Code Library" link in the top right corner of the page and then
click the "Authentication" button in the menu on the left.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

Scott Allen

Hi John:

It doesn't look like you need them, but check the IIS settings also.
Perhaps anonymous access has been disallowed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top