Getting 401.2  
Author Message
Noctufaber





PostPosted: ASMX Web Services and XML Serialization, Getting 401.2 Top

My asmx web service authenticates correctly through a browser, but I can't seem to get it to authenticate through my Windows Forms Application using a web referrence to my asmx via wsdl.  I keep getting a 401.2 error. 

IIS directory security is set to Integrated windows authentication only.

ASP.net application identity settings are set to local impersonation with username and password both set to blank.

ASP.net authorization rules are set to allow all users.

ASP.net authentication mode is set to Windows.

 

If I change the IIS directory security to allow anonymous access, the Windows Forms Application works, and authentication through the browser fails.

The environment is an intranet on a domain.  What do I need to do to have IIS directory security set to Integrated windows authentication only and allow my Windows Forms application to work

Oh, I'm working in VB.Net.

Thanks!



.NET Development18  
 
 
Noctufaber





PostPosted: ASMX Web Services and XML Serialization, Getting 401.2 Top

Found the solution:

I just need to add the following code:

MyWebService.Credentials = System.Net.CredentialCache.DefaultCredentials

Windows forms application now has the ability to successfully authenticate through Active Directory to the web service.


 
 
kulasti





PostPosted: ASMX Web Services and XML Serialization, Getting 401.2 Top

Where exactly did you add this code
 
 
Noctufaber





PostPosted: ASMX Web Services and XML Serialization, Getting 401.2 Top

I placed the code in my Windows Forms Application. Here is the code (note the highlighted areas):

Private Function PostFiles(ByVal theSession As String, _
ByVal theListFiles() As String, _
ByVal serverName As String, _
ByVal repositoryName As String, _
ByVal userName As String, _
ByVal passWord As String) As String()

Dim AnError(0) As String
AnError(0) = "PostFiles failed"

Try
Dim sendPostCommand As MVIServer.MVIxmlTools = New MVIServer.MVIxmlTools() ' the remote web service object
Dim webResponse() As String

sendPostCommand.Credentials = CredentialCache.DefaultCredentials ' essential for windows authentication with web server
webResponse = sendPostCommand.PostListFiles(theListFiles, _
serverName, _
repositoryName, _
userName, _
passWord, _
Principal.WindowsIdentity.GetCurrent.Name) ' the web service method call

LogMessage("PostFiles Completed", MessageType.Information)
Return webResponse
Catch ex As Exception
Return AnError
End Try
End Function