When I run the following code block; Even though the service address is correct, I get an error. What is the reason?
My code:
WSHttpBinding binding = new WSHttpBinding();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
if (scheme == "https")
{
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Mode = SecurityMode.Transport;
}
else
{
binding.Security.Mode = SecurityMode.None;
}
binding.Name = "MyServiceSoap";
binding.CloseTimeout = TimeSpan.MaxValue;
binding.OpenTimeout = TimeSpan.MaxValue;
binding.ReceiveTimeout = TimeSpan.MaxValue;
binding.SendTimeout = TimeSpan.MaxValue;
binding.MaxBufferPoolSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
X509Certificate2 serverCert = new X509Certificate2(Encoding.UTF8.GetBytes("kvfhgfucjfcvbıclngffsdıfgbuhb");
EndpointIdentity identity = EndpointIdentity.CreateX509CertificateIdentity(serverCert);
EndpointAddress endAddr = new EndpointAddress(new Uri(url + "/UserService.svc"), identity);
ApiService.UserServiceClient srv = new ApiService.UserServiceClient(binding, endAddr);
srv.ClientCredentials.UserName.UserName = "auth";
srv.ClientCredentials.UserName.Password = "hugghu!.";
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
System.Net.ServicePointManager.Expect100Continue = false;
var list = srv.GetAllByUsers();
Error:
System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://..... that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
What I tried:
if (scheme == "https")
{
srv.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication()
{
CertificateValidationMode = X509CertificateValidationMode.None,
};
}
ServicePointManager.ServerCertificateValidationCallback +=(sender, cert, chain, sslPolicyErrors) => true;
ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };