Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new ServiceReference1.Service1SoapClient().HelloMom("Bob");
- 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"));
- }
- }
- MyWebService svc = new MyWebService();
- svc.Credentials = new System.Net.NetworkCredential(UserID, pwd);
- bool result = svc.MyWebMethod();
- 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
- }
- }
- }
- MyWebService svc = new MyWebService();
- svc.AuthenticationHeaderValue = new MyWebService.AuthenticationHeader();
- svc.AuthenticationHeaderValue.UserName = UserID;
- svc.AuthenticationHeaderValue.Password = Password;
- bool result = svc.MyWebMethod();
- <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>
- proxy.ClientCredentials.UserName.UserName = userName;
- proxy.ClientCredentials.UserName.Password = password;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement