SOAP请求可在NodeJS中使用,但不能在.NET中使用

时间:2018-10-09 22:14:49

标签: javascript .net node.js web-services soap

我有以下两组代码,我们在其中进行邮寄请求。 Node Js能够建立连接,而.NET代码甚至无法打开流。您能给我指出.NET代码有什么问题吗?

NodeJS

    var fs = require('fs');
var https = require('https');

var post_data = fs.readFileSync('query.xml', 'utf-8');

var post_options = {
    hostname: 'test.something.org',
    port: 4437,
    path: '/Gateway/PatientDiscovery/',
    method: 'POST',
    key: fs.readFileSync('keyonly.pem'),
    cert: fs.readFileSync('certonly.crt'),
    ca: fs.readFileSync('crtchain2018.pem'),
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Content-Length': Buffer.byteLength(post_data)
    }
};

// Set up the request
var post_req = https.request(post_options, function (res) {
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
        console.log('Response: ' + chunk);
    });
});

try
{
// post the data
post_req.write(post_data);
post_req.end();
} catch(ex)
{
        console.log('Error' + ex);
}

这是类似的.NET代码,总是会引发异常

try
        {
            string endPoint = @"https://test.something.org:4437/Gateway/PatientDiscovery/;
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(endPoint);
            webRequest.Headers.Add(@"SOAP:Action");
            webRequest.ContentType = "application/x-www-form-urlencoded;charset=\"utf-8\"";
            webRequest.Method = "POST";
            return webRequest;

            request.ClientCertificates.Add(GetCert("keyonly.pem"));
            request.ClientCertificates.Add(GetCert("certonly.crt"));
            request.ClientCertificates.Add(GetCert("crtchain2018.pem"));

            XmlDocument soapEnvelopeXml = new XmlDocument();
            soapEnvelopeXml.LoadXml(GetXml());// query.xml
            ServicePointManager.CheckCertificateRevocationList = false;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            ServicePointManager.ServerCertificateValidationCallback += AcceptCerts;


            using (Stream stream = request.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }


            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {
                    string soapResult = rd.ReadToEnd();
                    Console.WriteLine(soapResult);
                }
            }
        } catch(Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

能否让我知道.NET代码有什么问题?

谢谢 尚卡拉

0 个答案:

没有答案