Proxy Authentication Error while calling FedEx webservice - c#

I am trying to call the FedEx tracking webservice. Currently I am running the sample application provided by FedEx itself (Added my test account number and other details). When I run the application, I get the following error:
The remote server returned an error: (407) Proxy Authentication Required.
I am inside a proxy at my organization and I tried provided the proxy server details to the webservice client using the WebProxy class as:
trackService.Proxy = WebProxy.GetDefaultProxy();
and also by providing the proxy server details as:
trackService.Proxy = new WebProxy("IP",8080);
But I still keep getting the same error!! Could somebody help me how to resolve this problem?
Thanks in advance,
Regards,
Abdel Olakara

What you seem to be missing is the proxy credentials. Try this:
trackService.Proxy = new WebProxy("IP", 8080);
trackService.Proxy.Credentials = new NetworkCredential(
username, password, domain);

Related

How to fix "The HTTP request was forbidden with client authentication scheme 'Anonymous'"

I'm having some issues implementing a client that talks to a WCF service. It's a WCF hosted by another company so I don't have access to its code. I used the Connected Service provider tool in Visual Studio to generate the client code so that I could make requests and everything works fine on my local machine. I am having an issue on our development environment where I receive the following error if I try to make a request with the client:
The HTTP request was forbidden with client authentication scheme 'Anonymous'
I've been looking at the client code (it's a lot of code) which is generated by the Provider tool and I think it may have something to do with the following block of code.
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
return result;
This more linked to firewall rules within corporate network.
I had same issue using non authorized proxy but got resolved secured proxy with ntlm ClientCredentialType
This error typically indicates that the WCF server authenticates the client-side with a certificate. The error will occur when the trust relationship between the server and the client have not been established yet.
In general, we need to provide client credential to be authenticated by the server so that be able to call the service. As for what kind of credentials need to be provided, it depends on the binding information on the server-side.
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
Namely, the above errors have indicated that the server authenticates the client with a certificate.
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
About authenticating the client with a certificate, you could refer to the below link for details.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication
Feel free to let me know if there is anything I can help with.
Thanks for all the suggestions. This was actually just caused by a firewall rule that was setup within our organisation. Once that was removed the code worked as expected.
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
Security is provided using HTTPS. The service must be configured with SSL certificates. The SOAP message is protected as a whole using HTTPS. The service is authenticated by the client using the service's SSL certificate. The client authentication is controlled through the ClientCredentialType.
https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.basichttpsecuritymode?view=netframework-4.8

How to set Password Type in C# while consuming a SOAP web service

I am trying to consume a third-party SOAP web service in my C# console app. I tried two different way of passing the credentials as shown below.
//Method 1 - passing security credentials
myCardService.Credentials = new System.Net.NetworkCredential("username",
"password");
//Method 2 - passing security credentials
System.Net.CredentialCache myCredentials = new System.Net.CredentialCache();
NetworkCredential netCred = new NetworkCredential("username", "password");
myCredentials.Add(new Uri(myCardService.Url), "Basic", netCred);
myCardService.Credentials = myCredentials;
In both the cases, I am getting this exception:
System.Web.Services.Protocols.SoapHeaderExceptions: Error in SecurityHeader: An Invalid security token was provided
When I tried SOAP UI to consume the service, there also I got the same error. However, when I made WSS-Password Type = PasswordText in the Properties window of the tool, then it worked. I don't see any way to make this setting in the credential objects in the C# code. Any help is greatly appreciated.
My understanding, that after you define your service binding to the authentication type.
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
After you have defined the authentication type, you would create your web service client and do the following:
client.ClientCredentials.Username.Username = networkCredential.Username;
client.ClientCredentials.Password.Password = networkCredential.Password;
That should be the appropriate manner to pass those credentials.
The issue was resolved after I installed WSE 3.0 from https://www.microsoft.com/en-us/download/details.aspx?id=14089 and changed the web reference manually from System.Web.Services.Protocols.SoapHttpClientProtocol to Microsoft.Web.Services3.WebServicesClientProtocol in the Reference.cs file.

Consuming webservice from wsdl with basic authentication from asp.net

I have a WSDL file. I want to consume webservice from this WSDL. I have added service reference by using this WSDL and created proxy. I have created required parameter for invoking my service method. Actually webservice is protected by a basic authentication. But in the client proxy no option found to provide the user name and password. How could I invoke webservice?
I want to provide basic authentication credentials.
I am getting the following error when invoking service method without giving credentials.
System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
Please help me
Try this:
client.ClientCredentials.UserName.UserName = "xxxxxx";
client.ClientCredentials.UserName.Password = "xxxxx";
https://msdn.microsoft.com/en-us/LIbrary/ms733775.aspx

Nothing showed when browsing ews Exchange.asmx

Since yesterday, I tried to use the exchange web service but it was not able. Firstly when I was trying to access to the web service by the browser and the test program using Microsoft.Exchange.WebServices, there was an error 403 forbidden. But this issue I solved by unchecking require SSL option in IIS. And now the problem is when I try to access on the ews using my program, I encounter 401 unauthorized error, and if I try to browse the web service on the browser, only an empty page is returned (even when I browse the wsdl).
I tried to change the role and the password but it was not working.
Please help me to find out what I am missing.
Here is my test program code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new WebCredentials(username, password, domain);
service.Url =new Uri("server/EWS/Exchange.asmx");
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnValidationCallback);
ExpandGroupResults groupResults = service.ExpandGroup(emailAddress);
The exception is on the last line
I found why the XML for the ews was not showing. It was because the IIS was not installed with basic authentication and Windows authentication. After installing those two authentication method, the web service shows its xml.
This is the link I referred: https://migrationwiz.zendesk.com/entries/506613-how-do-i-verify-ews-is-setup-properly

The remote server returned an error: (401) Unauthorized - Azure's OAUTH implementation (WRAP)

I have a WCF Rest service that I am trying to integrate with Azure's ACS in order to validate requests from the clients.
I am trying to use one of the tests placed here :
http://msdn.microsoft.com/en-us/library/windowsazure/hh674475.aspx#BKMK_1
This is my code :
string wrapUsername = "account#hotmail.com";
string wrapPassword = "aPass123";
// request a token from ACS
WebClient client = new WebClient();
client.BaseAddress = string.Format("https://glamstsecure.accesscontrol.windows.net");
NameValueCollection values = new NameValueCollection();
values.Add("wrap_name", wrapUsername);
values.Add("wrap_password", wrapPassword);
values.Add("wrap_scope", "uri:WindowsLiveID");
byte[] responseBytes = client.UploadValues("WRAPv0.9/", "POST", values); <- Here i am getting The remote server returned an error: (401) Unauthorized
Scope is supposed to be the authentication authority right?
wrap_scope should be the realm of your relying party application in the ACS portal.
Also, you may want to take a closer look at this solution. It's intended to be used with service identities that you configure in your ACS namespace.
Ia m runing into the same issue when trying to use GoogleId/password. it works fine for ServiceIdentity. But always throws a 401 error when using anything else. Also, Rick Rainey, Can you please elaborate on why the above code can only be used for ServiceIdentities as specified by you?

Categories

Resources