I am developing an application in which I have to use a webservice developed in Java using the http protocol. I am developing an application using C # .NET winforms.everything works fine until now.but, now the web service uses ssl security, so the service url protocol is changed from http to https. Now I am fixing problems accessing the https web service.
I tried to access the https web service from SoapUI by providing the Authenticaion Parameter parameters (UserName and Password) on the Auth tab, as shown below:

It works great from SoapUI.
but wen I am providing Authenticaion parameters from the code as shown below:
client.ClientCredentials.UserName.UserName = "admin"; client.ClientCredentials.UserName.Password = "*******";
I use security mode like: TransportWithMessageCredential as well as ClientCredentialTtype as: Basic
My App.Config file is as follows:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <system.serviceModel> <client> <endpoint address="https://xyz:8001/HelloWorldAPI/HelloWorldWebService" binding="wsHttpBinding" bindingConfiguration="myhttpsbinding" contract="API.HelloWorldWebService" name="HelloWorldWebServicePort" /> </client> <bindings> <wsHttpBinding> <binding name="myhttpsbinding"> <security mode="TransportWithMessageCredential"> <transport clientCredentialType="Basic"/> </security> </binding> </wsHttpBinding> </bindings> </system.serviceModel> <system.net> <defaultProxy useDefaultCredentials="true" /> </system.net> </configuration>
My code is as below:
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.Text; using System.Threading.Tasks; using testingtool.API; namespace testingtool { class Program { static void Main(string[] args) { new APITool(); } } class APITool { UserInfo userinfo = new UserInfo(); HelloWorldWebServiceClient client = new HelloWorldWebServiceClient(); private bool ValidationCallBack(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error) { return true; } public APITool() { try {
I get the following exception:
System.ServiceModel.Security.MessageSecurityException: An HTTP request was not authorized using the Anonymous client authentication scheme. The authentication header received from the server was "Primary realm =" EJBServiceEndpointServlet Realm "'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
EDIT: from the client, I checked with Fiddler the request window, as shown below: from the AUth tab, it says that there is no Autherization Header header.

Fiddler Raw request as below:
CONNECT 10.10.10.110:8001 HTTP/1.1 Host: 10.10.10.110:8001 Connection: Keep-Alive User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
any help would be greatly appreciated.