Cannot find the X.509 certificate using the following search criteria: StoreName 'My', StoreLocation 'CurrentUser', FindType 'FindBySubjectName', FindValue 'ToanChet'.
How to solve this error ?
How to solve this error ?
Hi every body,
we use .NET framework ( website ,windows forms) in our company , I need to consume a wep api from another company which is built using java, and they need to authenticate the client using certificates
the company API interface is simple, they use a REST technology over https with JSON data exchange, the asked to send Exchange certificate: "We need you to send us a public key of your SSL certificate. If you don't have a commercial one, you can issue a self signed one (Note: if you use java you can use the 'keytool' utility). Then we will install your certificate as a trusted peer so that we accept requests from you."
I send them a public key for a self signed certificate generated from IIS (X.509base 64 encoded), and they send me a sample java code for API CALL
package com.bisan.proj.act; import java.io.FileInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.URL; import java.security.KeyStore; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; import com.google.gson.Gson; public class ApiTest_currency { private static final String myKeyStore = ""; //TODO this is your private key store. private static final String myKeyPass = "";//TODO keystore password private static final String account = ""; //TODO bisan account private static final String user = ""; //TODO user private static final String password = ""; //TODO password private static SSLSocketFactory sslFactory = null; private static SSLSocketFactory getFactory() throws Exception { if (sslFactory == null) { KeyStore clientKeyStore = KeyStore.getInstance(KeyStore.getDefaultType()); clientKeyStore.load(new FileInputStream(myKeyStore), myKeyPass.toCharArray()); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory .getDefaultAlgorithm()); kmf.init(clientKeyStore, myKeyPass.toCharArray()); SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(kmf.getKeyManagers(), null, null); sslFactory = ctx.getSocketFactory(); } return sslFactory; }//getFactory public static void main(String[] args) throws Exception { System.out.println(createRequest()); URL url = new URL("https://gw.bisan.com/api/" + account); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setSSLSocketFactory(getFactory()); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoInput(true); connection.setDoOutput(true); //set the request OutputStream out = connection.getOutputStream(); out.write(createRequest().getBytes()); out.close(); int status = connection.getResponseCode(); System.out.println(status + " " + connection.getResponseMessage()); if (status == 200) handleResponse(connection.getInputStream()); }//main /* JSON Request * { * "user" : "test", * "password" : "12345", * "command" : "table", * "table" : "currency", * "filters" : [ {"field" : "code", * "operation": "!=", * "value" : "01" } * ], * * "fields" : ["symbol", "rate"] * } * */ private static String createRequest() { Map<String, Object> request = new HashMap<String, Object>(); request.put("user", user); request.put("password", password); request.put("command", "table"); request.put("table", "currency"); ArrayList filters = new ArrayList(); Map f1 = new HashMap(); f1.put("field", "code"); f1.put("operation", "!="); f1.put("value", "01"); filters.add(f1); request.put("filters", filters); ArrayList fields = new ArrayList(); // fields.add("code"); // fields.add("name"); fields.add("symbol"); fields.add("rate"); request.put("fields", fields); Gson gson = new Gson(); return gson.toJson(request); }//createRequest /* JSON Reply * { * "command" : "table", * "table" : "currency", * "error" : "", * "filters" : [ { "field" : "code", * "operation" : "!=", * "value" : "01" } * ], * * "fields" : [ "symbol", "rate"], * * "rows": [ {"symbol":"USD" ,"rate":"3.86000"}, * {"symbol":"JD" ,"rate":"5.41000"}, * {"symbol":"4" ,"rate":"0.70900"} * ] * } * */ private static void handleResponse(InputStream in) { Gson gson = new Gson(); Map reply = gson.fromJson(new InputStreamReader(in), Map.class); System.out.println("\nerror: " + reply.get("error")); if (reply.get("error") != null) return; List<Map> rows = (List<Map>) reply.get("rows"); System.out.println("rows " + rows.size()); for (Map m : rows) System.out.println(m.get("symbol") + " " + m.get("rate")); }//handleResponse }//class
I served the net to find the equivalent code for sending Client Request with Certificate in .NET but I get lost in articles, I can't distinguish between X509Certificate and X509Certificate2 which one to use and the path of my private key, should I only provide the path, or locate it from the store (MMC)
my code Trial
using System; using System.Net; using System.Security.Cryptography.X509Certificates; class Program { class MyWebClient : WebClient { // private ssl key info string myKeyStore = @"C:Key.pfx"; string myKeyPass = ""; //password protected override WebRequest GetWebRequest(Uri address) { HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address); X509Certificate cert2 = new X509Certificate(myKeyStore, myKeyPass); request.ClientCertificates.Add(cert2); return request; } } static void Main(string[] args) { // Bisan Demo Account string account = ""; string user = ""; string Bisanpassword = ""; var client = new MyWebClient(); var data = client.DownloadString("https://gw.bisan.com/api/" + account); Console.WriteLine(data); } }
but this didn't work
any help please
Dear all programmer,
I have any problem about how to create custom authentication in wcf service. i have research any resources and try to follow it, but it still error
Can anyone help me or share me with resource or link ?
Dear all programmer !
when client request to my wcf url they need to login with header if username and password are wrong they can not use my wcf service
Have any resource please help share me !
Hello all programmer !
How can i disable wsdl file in my WCF service that show as XML on browser, but i can access that wsdl file when i add reference inadd service reference in C# client and i can access all its method as normal.
Thank for your help !
I have a set of services in my web service. every one should be authenticated before accessing any one of service. To achieve this, i want to add a login page in web service project with form authentication. is it possible?
1) we can create proxy of wcf at client pc to connect the web service but i saw people use some time wcf channel factory to connect wcf service from client application but i want to know why some one will use wcf channel factory instead of creating proxy at client pc?
2) please tell me few scenario when people use wcf channel factory ?
3) wcf channel factory provide any kind of security for web service ?
4) what is advantage of wcf channel factory ?
5) please tell me Client can use WCF channel factory to connect when mex endpoint & httpGetEnabled both are disabled at service end ?
thanks
While Consuming SOAP based SVC service in Console .Net application, getting the error as "The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element".
Even i increased our maxReceivedMessageSize="2147483647" in config still issue not solved.
Hello ,
I need to set default domain of WCF SERVICE for basic authentication via PowerShell scripts. I need this to automate the deployment process.
IIS->DefaultWebsite->WCFService->Authentication-Basic->Edit->Set Default Name
Hi,
while consuming svc in client, facing the error as "The request channel timed out while waiting for a reply after 00:00:59.9529971. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a long".
I am using the below config settings.
<bindings>
<basicHttpBinding>
<binding name="BasicHttpsBinding" closeTimeout="00:50:00" openTimeout="00:50:00" receiveTimeout="00:50:00" maxReceivedMessageSize="99999999" maxBufferSize="99999999" maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="32" maxArrayLength="2147483647" maxStringContentLength="2147483647" />
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
Any other settings need to modify in web.config.
I am in the process of moving my asmx web service from one machine to a load balanced setup of two machines. There are no issues on the single machine setup. However on the load balancing setup, I have run into an issue when trying to invoke the service call. I can get to the services fine. When I invoke the call, I get an application timeout from the load balancer itself. On further investigation, I have noticed that the Host listed on the operations page is the load balancer IP. I believe this is the problem, but I do not have enough knowledge to know so.
Hi,
I am trying to access an asmx service which requires basic authentication using .net core 2.0
Basically i did the following.
I am very new to write WCF for Insert, deletion and updatation using WCF
Hi ,
I have a web page which dispaly user input fields . "firstname" , "lastname" etc
How can i get a windows service to get the data in the input fields and write the data to a database ?
I have a solution with a web app that gets the data and on a button click it inserts into a database , But i want it so that the button is clicked then the windows service will insert the data.
Thanks
Hello all,
I have a WCF service that is set to take Basic authentication. I have created a JS POC and trying to call WCF service thru it. I am passing credentials in javascript. Basically I wanted to implement Basic auth in JS.
My svc code: (Web.config)
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.serviceModel>
<services>
<service name="BasicAuthenticationDemo.Service1">
<endpoint binding="webHttpBinding" contract="BasicAuthenticationDemo.IService1" bindingConfiguration="CustomBasicBinding" behaviorConfiguration="ServiceBehavior" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="CustomBasicBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="webBinding">
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="Basic"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceAuthorization serviceAuthorizationManagerType="BasicAuthenticationDemo.RestAuthorizationManager, BasicAuthenticationDemo"/>
<webHttp helpEnabled="True" />
<CorsSupport />
</behavior>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
</customHeaders>
</httpProtocol>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
--------
[ServiceContract]
public interface IService1
{
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
string WelcomeUser(string userName);
}
---------
public class RestAuthorizationManager: ServiceAuthorizationManager
{
/// <summary>
/// Method source sample taken from here: http://bit.ly/1hUa1LR
/// </summary>
protected override bool CheckAccessCore(OperationContext operationContext)
{
WriteEventLog("CRM service authenticator: Step 1", EventLogEntryType.Error);
//Extract the Authorization header, and parse out the credentials converting the Base64 string:
var authHeader = WebOperationContext.Current.IncomingRequest.Headers["Authorization"];
WriteEventLog("CRM service authenticator:" + authHeader, EventLogEntryType.Error);
if ((authHeader != null) && (authHeader != string.Empty))
{
WriteEventLog("CRM service authenticator: authheader not null", EventLogEntryType.Error);
var svcCredentials = System.Text.ASCIIEncoding.ASCII
.GetString(Convert.FromBase64String(authHeader.Substring(6)))
.Split(':');
var user = new
{
Name = svcCredentials[0],
Password = svcCredentials[1]
};
WriteEventLog("CRM service authenticator: username=" + user.Name, EventLogEntryType.Error);
WriteEventLog("CRM service authenticator: password=" + user.Password, EventLogEntryType.Error);
if ((user.Name == "xxxtest\\xxx.crmdeploy" && user.Password == "xxx@"))
{
//User is authrized and originating call will proceed
return true;
}
else
{
//not authorized
return false;
}
}
else
{
//No authorization header was provided, so challenge the client to provide before proceeding:
WebOperationContext.Current.OutgoingResponse.Headers.Add("WWW-Authenticate: Basic realm=\"MyWCFService\"");
//Throw an exception with the associated HTTP status code equivalent to HTTP status 401
throw new WebFaultException(HttpStatusCode.Unauthorized);
}
}
private void WriteEventLog(string message, EventLogEntryType type)
{
const string sSource = "CRM service authenticator";
const string sLog = "Application";
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
EventLog.WriteEntry(sSource, message);
}
}
---------
My JS Code:
<!DOCTYPE html>
<html>
<head>
<title>Auth</title>
<meta charset="utf-8" />
<script type="text/javascript" src="jquery_2.0.3.min.js"></script>
<script type="text/javascript">
function CheckAuth() {
var crmProxy = "http://crm.com:555/dev_test/Service1.svc";
var name = "xxxtest\\xxx.crmdeploy";
var pwd = "xxx@";
var authorizationInfo = "Basic " + btoa(name + ':' + pwd);
var text = "Parshu";
var response = null;
$.support.cors = true;
$.ajax({
//async: true,
type: "POST",
url: crmProxy + "/WelcomeUser",
//xhrFields: {
// withCredentials: true
//},
//crossDomain: true,
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', "Basic " + authorizationInfo);
},
contentType: "application/json; charset=utf-8",
data: '{"userName": "' + text + '" }',
//headers: {
// "Authorization": "Basic " + authorizationInfo
//},
success: function (result) {
response = result.WelcomeUserResult;
alert(response);
},
error: function (xhr, ajaxOptions, throwError) {
//debugger;
alert("err");
}
});
}
</script>
</head>
<body>
<a>Auth example</a><br />
<input type="button" name="Submit" onclick="CheckAuth()" value="Submit" />
</body>
</html>
Request you to please guide me where I am going wrong.
I am getting this error : XMLHttpRequest: Network Error 0x80070005, Access is denied.
-Prashant
Hi
I have to work with a remote soap service without access to it. I only have the wsdl file so I can create the service reference but the problem is how can I simulate that service?
Dear all,
In my current project, i have classes with more than 100 properties. i am using WCF service to retrieve data and view it as required in the application. During execution of the application, there are different scenarios and with each scenario i need different properties of a class. sometime 3, sometime 8, sometime 15 properties etc. As the class is very big, i want to return only those properties that don't have null value or properties have values other than null value should return from wcf service [to reduce load and avoid unnecessary data]. so finally i need only the 3, 8, 15 properties from wcf service method call.
the wcf service is using wshttpbinding and i am working on mvc web application where call to the wcf is done using ajax whenever required. this requirement is specially for this ajax call response data that vary on different scenarios.
please tell how i can do this more efficiently. please share code snippet to help me.
Many Thanks
I have imported the web reference from wsdl file in to my asp.net web application. Also i have build my web service with TLS 1.2, to access the web service i have to pass the below header authentication while accessing the method.
X-IBM-Client-Secret X3yI1dK4cA4rP4fO8sF6wD4xR2wX1nQ8cR5oO1yQ4eF4iX0cL3
X-IBM-Client-Id af829919-5ea9-49ee-96b6-2b60fa3babf2
Also please find the below code i have used to access the details from web service.
ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12;XmlNode nodeVerfiedResult = objPANInquiry.GetPanStatus(txtPANNo.Text,"DIGITALDOST","1500000004","Pass@123","");XElement elementVerfiedResult =XElement.Parse(nodeVerfiedResult["APP_PAN_INQ"].OuterXml);string strAppStatus = elementVerfiedResult.Descendants("APP_STATUS").Select(x => x.Value).ToArray()[0].ToString();
Please guide me to add the above mentioned header in my application. Thanks in advance.
Please share code snippet to help me.
Many Thanks..
I am using WCF service to retrieve large amount of data from database (about 20,000) record.
what is the required configuration in web.config to handle this issue?
thanks