I am trying to send a request to an ASMX service using my code. The code works perfectly on my local machine, and I receive a correct response there. Additionally, sending the request via SoapUI on the server also works as expected. However, when I execute the same code on the server, I encounter the following error:
Could not establish trust relationship for the SSL/TLS secure channel with authority 'pec.shaparak.ir'
SOAP Request in SoapUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sal="https://pec.Shaparak.ir/NewIPGServices/Sale/SaleService">
<soapenv:Header/>
<soapenv:Body>
<sal:SalePaymentRequest>
<!--Optional:-->
<sal:requestData>
<!--Optional:-->
<sal:LoginAccount>**********</sal:LoginAccount>
<sal:Amount>1046673000</sal:Amount>
<sal:OrderId>111111111</sal:OrderId>
<!--Optional:-->
<sal:CallBackUrl>********</sal:CallBackUrl>
<!--Optional:-->
<sal:AdditionalData>?</sal:AdditionalData>
<!--Optional:-->
<sal:Originator>*******</sal:Originator>
</sal:requestData>
</sal:SalePaymentRequest>
</soapenv:Body>
</soapenv:Envelope>
Code:
[HttpPost("TestParsian")]
public async Task TestParsian([FromBody] PaymentRequest request)
{
ParsianSales.SaleServiceSoapClient.EndpointConfiguration endpointConfiguration;
endpointConfiguration = ParsianSales.SaleServiceSoapClient.EndpointConfiguration.SaleServiceSoap12;
var srv = new ParsianSales.SaleServiceSoapClient(endpointConfiguration);
#region
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
srv.Endpoint.Binding = binding;
#endregion
System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => { Console.WriteLine("ssl"); return true; };
ParsianSales.ClientSaleRequestData saleRequest = new()
{
LoginAccount = request.LoginAccount,
Amount = request.Amount,
Originator = request.Originator,
OrderId = (long)Convert.ToDouble(request.OrderId),
CallBackUrl = request.CallBackUrl
};
Console.WriteLine("before");
var result = srv.SalePaymentRequest(saleRequest);
Console.WriteLine(result.Message);
Console.WriteLine(result.Token);
}
Troubleshooting Steps Taken:
I have tried setting the TLS protocol version:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
I configured the server to accept the certificate.
I tested the code in a loop to see if retrying would succeed, but the problem persists.
I should also note that sometimes when I execute the request in SoapUI, it either fails or takes a long time to complete, while my code doesn’t receive a response at all.