Friday, March 30, 2007

How to call asp.net webservice with windows authentication set?

at the server:
1) create webservice using vs.net
2) create proxy.vb using webservice wsdl by issuing the command at vs.prompt:
wsdl /l:vb /o:Service1Proxy.vb http:/localhost/service1.asmx?wsdl

3) compile proxy
vbc /t:library /libpath:x:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\ /r:System.Web.Services.dll /r:System.Xml.dll /r:System.dll Service1Proxy.vb

4) install the webservice with "integrated windows authentication" enabled.

at the client:
1) reference webservice proxy assembly
2) call the web method
3) set webservice url.
obj.Url = "http://xxxx/webservice1/service1.asmx"

4) this will pass windows identity to web service.
add in web.config file of the asp.net page calling a web service.

5) if you wish to pass userid/pass directly from the client to webservice use this:
Dim cache As New CredentialCache
Dim cred As New NetworkCredential("userid", "pass", "domain")
cache.Add(New Uri(obj.Url), "NTLM", cred)
obj.Credentials = cache


6) do async call (so as no to tie up threads from the pool)
Dim res As IAsyncResult = obj.BeginHelloWorld(Nothing, Nothing)
Response.Write(obj.EndHelloWorld(res))

* also try Async HTTPHANDLER

0 Comments:

Post a Comment

<< Home