ASMX username and password

I have a basic ASMX service that I am trying to start (I would prefer to use WCF, but I cannot get the server to work with it). It works great in security settings, but as soon as I turn on protection, I get:

The HTTP request is not authorized using the Anonymous client authentication scheme. The authentication header received from the server was "Basic realm =" Secure Area ".

What I want is a minimalistic user request for a username and password.

Washing code with intellisense will not come up with anything like me.

It looks like it might be useful, but it looks like it is a WCF that knows.


I just realized that I can do this live demo:

here is the service: http://smplsite.com/sandbox3/Service1.asmx

The username is testapp , and the password is testpw . I need a command line application that calls the functions of this service.

If I added security, this line worked in the VS base project after running the Add Web Service Reference at this URL

 new ServiceReference1.Service1SoapClient().HelloMom("Bob"); 

This is my current attempt (this does not work)

 class Program { private static bool customValidation(object s, X509Certificate c, X509Chain ch, SslPolicyErrors e) { return true } static void Main(string[] args) { // accept anything ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(customValidation); var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; binding.Security.Transport.Realm = "Secured area"; // the generated Web Service Reference class var client = new ServiceReference1.Service1SoapClient( binding, new EndpointAddress("https://smplsite.com/sandbox3/Service1.asmx") ); client.ClientCredentials.UserName.UserName = "testapp"; client.ClientCredentials.UserName.Password = "testpw"; Console.WriteLine(client.HelloMom("Bob")); } } 

Edit: BTW is not a website or works in a browser, access code is a command line application in C #. In addition, authentication is performed by another IIS plug-in, which I do not control.

Edit 2: be clear; The solution I'm looking for is a purely client problem.

Edit 3: Access control is done through a system such as .haccess , and I like it. I do not want the service code to authenticate.

+6
login web-services asmx
source share
3 answers

Edit:
How about this:

 MyWebService svc = new MyWebService(); svc.Credentials = new System.Net.NetworkCredential(UserID, pwd); bool result = svc.MyWebMethod(); 

The OP says that this will not work, and now I see that it will not be in his situation.

We are doing something like this:

 public class MyWebService : System.Web.Services.WebService { public AuthenticationHeader AuthenticationInformation; public class AuthenticationHeader : SoapHeader { public string UserName; public string Password; } [WebMethod( Description = "Sample WebMethod." )] [SoapHeader( "AuthenticationInformation" )] public bool MyWebMethod() { if ( AuthenticationInformation != null ) { if ( IsUserAuthenticated( AuthenticationInformation.UserName, AuthenticationInformation.Password, ref errorMessage ) ) { // Authenticated, do something } else { // Failed Authentication, do something } } else { // No Authentication, do something } } } 

Please note that you are supplying IsUserAuthenticated ().

Then the client calls it like this:

  MyWebService svc = new MyWebService(); svc.AuthenticationHeaderValue = new MyWebService.AuthenticationHeader(); svc.AuthenticationHeaderValue.UserName = UserID; svc.AuthenticationHeaderValue.Password = Password; bool result = svc.MyWebMethod(); 
+12
source share

I am going to add a new answer because I think this may help:

http://intellitect.com/calling-web-services-using-basic-authentication/

I will not duplicate it here because I did nothing except Google.

+2
source share

Config:

 <binding name="MyBinding" closeTimeout="00:00:30" openTimeout="00:00:30" receiveTimeout="00:00:30" sendTimeout="00:00:30" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" messageEncoding="Text"> <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="Transport"> <transport clientCredentialType="Basic" realm=""/> </security> </binding> </basicHttpBinding> 

During use

 proxy.ClientCredentials.UserName.UserName = userName; proxy.ClientCredentials.UserName.Password = password; 

It worked fine for me.

0
source share

All Articles