default system proxy settings - c#

I'm going to sent SOAP-request to the host via proxy. I use two variants: manual proxy settings and system proxy settings. There is my code:
if (UseProxy.Equals("manual"))
{
WebProxy p = new WebProxy(pServer, true)
{
Credentials = new NetworkCredential(ProxyUser, ProxyPass)
};
WebRequest.DefaultWebProxy = p;
Request.Proxy = p;
Request.Timeout = 10000;
}
else if(UseProxy.Equals("system"))
{
IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = CredentialCache.DefaultCredentials;
Request.Proxy = proxy;
Request.Timeout = 10000;
}
Manual settings are working well, but system proxy settings don't work at all. I can not send anything and program hangs out on request regardless of the timeout parameter.
Also I tried the following:
WebProxy proxy = new WebProxy(ProxyHost, 8080);
proxy.UseDefaultCredentials = true;
Request.UseDefaultCredentials = true;
WebRequest.DefaultWebProxy = proxy;
Request.Proxy = proxy;
Request.Timeout = 10000;
It didn't work too. Please explain me where is my error? Class with SOAP-requests was generated authomatically using wsdl-file.

Related

Webservice HttpStatusCode 500 but not in browser

When I start a new HttpBasicBinding to a web service which is not initiated yet, because the app pool is not started will result in an Internal Server Error 500. But when I start the Web Service from the browser the service is being started.
How can I start the web service before sending a new request?
Below my code:
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
binding.Name = "AXDocumentBinding";
EndpointAddress address = new EndpointAddress(serviceUrl);
AA_DynamicsAXDocuHandlingClient cls = new AA_DynamicsAXDocuHandlingClient(binding, address);
cls.ClientCredentials.Windows.ClientCredential = new NetworkCredential(username, password, domain);
string retVal = cls.loadDocumentStr(AreaId, documentFileName, documentIdentification1, documentIdentification2, documentIdentification3, documentIdentification4, documentIdentification5, documentTable);
Thanks in advance

webdriver - Setting a proxy for IE in C#

Is it possible to set a proxy programatically in webdriver for IE?
For Chrome, I do something like this:
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.HttpProxy = "http://proxy.com:8080";
proxy.SslProxy = "http://proxy.com:8080";
options.AddAdditionalCapability("proxy", proxy);
but this doesn't work for IE. I've also tried: options.AddAdditionalCapability(CapabilityType.Proxy, proxy); which doesn't work. Is there a comparable capability for IE?
Have you tried the latest IEDriverServer (version 2.34.0.0)? This is feature is very new to the IEDriverServer. The .NET bindings now expose the Proxy via the InternetExplorerOptions class.
This is the change log: https://code.google.com/p/selenium/source/detail?r=084758c6b515a2699b82c6bf5871e29b552cbc8f
You should be able to do the exact same thing now after updating the IEDriverServer and .NEt bindings:
InternetExplorerOptions options = new InternetExplorerOptions();
Proxy proxy = new Proxy();
proxy.HttpProxy = "http://proxy.com:8080";
proxy.SslProxy = "http://proxy.com:8080";
options.Proxy = proxy;
String PROXY = url://login:pass#proxy:port";
ChromeOptions options = new ChromeOptions();
options.AddArguments("user-data-dir=path/in/your/system");
Proxy proxy = new Proxy();
proxy.HttpProxy = PROXY;
proxy.SslProxy = PROXY;
proxy.FtpProxy = PROXY;
options.Proxy = proxy;
// Initialize the Chrome Driver
using (var driver = new ChromeDriver(options))

Post Status in LinkedIn

I saw one artcle how to share our status in LinkedIn using c#.
I follow those steps and the code I am using is following...
For this I am using Hammock library.
OAuthCredentials credentials = new OAuthCredentials();
credentials.Type = OAuthType.AccessToken;
credentials.ConsumerKey = "****";
credentials.ConsumerSecret = "*****";
credentials.Token = "******";
credentials.TokenSecret = "*********";
credentials.SignatureMethod = OAuthSignatureMethod.HmacSha1;
credentials.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader;
RestClient client = new RestClient();
client.Authority = "http://api.linkedin.com/v1";
client.Credentials = credentials;
client.Method = WebMethod.Put;
byte[] msg = Encoding.Default.GetBytes("Test");
client.AddHeader("Content-Type", "text/xml");
client.AddPostContent(msg);
RestRequest request = new RestRequest();
request.Path = "http://api.linkedin.com/v1/people/~/current-status";
/* ERROR */ RestResponse response = client.Request(request);
It's giving me a error "Bad Request."
How to solve this please help me..?

(407) Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied

I know that this error is very common, but I tried to apply the solutions to this problem and could not solve it.
Thats my code:
var endpoint = new EndpointAddress(new Uri("http://www3prz.bancobonsucesso.com.br/Servicos/app.svc"), EndpointIdentity.CreateDnsIdentity("bancobonsucesso.com.br"));
var binding = new WSHttpBinding();
binding.UseDefaultWebProxy = true;
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.Security.Message.EstablishSecurityContext = true;
binding.Security.Message.NegotiateServiceCredential = true;
var customBinding = new CustomBinding(binding);
SymmetricSecurityBindingElement security = customBinding.Elements.Find<SymmetricSecurityBindingElement>();
security.LocalClientSettings.MaxClockSkew = TimeSpan.MaxValue;
security.LocalClientSettings.DetectReplays = false;
SecureConversationSecurityTokenParameters secureTokenParams = (SecureConversationSecurityTokenParameters)security.ProtectionTokenParameters;
SecurityBindingElement bootstrap = secureTokenParams.BootstrapSecurityBindingElement;
bootstrap.LocalClientSettings.MaxClockSkew = TimeSpan.MaxValue;
bootstrap.LocalClientSettings.DetectReplays = false;
ws = new ServicoClient(customBinding, endpoint);
ws.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
ws.ClientCredentials.UserName.UserName = "test";
ws.ClientCredentials.UserName.Password = "test";
var return = ws.EmitirBoleto("test");
IN the WCF Binding use useDefaultWebProxy:
<bindings>
<basicHttpBinding>
<binding name="bindingName" useDefaultWebProxy="true">
WebProxy wproxy = new WebProxy("new proxy",true);
wproxy.Credentials = new NetworkCredential("user", "pass");
WebRequest.DefaultWebProxy = wproxy;
This error may arise problem with proxy settings.
Please check Proxy setting with your web browser. Just changed connection settings Option -> settings -> connection settings to Auto detect proxy settings
Good luck ...

HttpClient with Authentication returns 404. Why?

I have an API that needs authentication with username and password. I can't figure out why my code fails and the response is 404, when I'm doing a GET method and give the actual credentials:
NetworkCredential networkCredentials = new System.Net.NetworkCredential("adminUN", "mypassword");
HttpClientHandler handler = new HttpClientHandler();
handler.PreAuthenticate = true;
handler.Credentials = networkCredentials;
httpClient = new HttpClient(handler);
HttpResponseMessage response = await httpClient.GetAsync(GlobalDeclarations.strURL);

Categories

Resources