通过nodejs状态代码错误415调用Web服务(Soap)

时间:2014-02-04 16:56:52

标签: node.js wcf soap

我试图通过节点js调用WCF Web服务(SOAP请求)。我得到415(不支持的媒体类型)http状态错误代码。知道我错过了什么吗?

var http = require('http');

var options = {    
  host:'localhost',
  port:'34563',
  path:'/Service1.svc',
  connection:'keep-alive',
  accept:'*/*',
  method:'POST',
  header: {
      'Content-Type':'text/xml;charset="UTF-8"',
      'Content-Length':data.length,
      'Accept':'*/*',
      'SOAPAction':'http://tempuri.org/IService1/GetData'
  }
};

var req=http.request(options, function(res) {
    console.log(res.statusCode);
    res.on('data', function(data) {
        console.log(data);
    });
    res.on('end', function() {

    });
    res.on('error', function(error) {
        console.log('1'+error);
    });
});

var data='<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+
  '<s:Body>'+
    '<GetData xmlns="http://tempuri.org/">'+
      '<value>12</value>'+
    '</GetData>'+
'</s:Body>' +
    '</s:Envelope>';


req.write(data);
req.end();

1 个答案:

答案 0 :(得分:0)

该死的...这个愚蠢的错误, 它应该是标题,'s'错过了。

var options = {    
  host:'localhost',
  port:'34563',
  path:'/Service1.svc',
  connection:'keep-alive',
  accept:'*/*',
  method:'POST',
  headers: {
      'Content-Type':'text/xml;charset="UTF-8"',
      'Content-Length':data.length,
      'Accept':'*/*',
      'SOAPAction':'http://tempuri.org/IService1/GetData'
  }
};


var req=http.request(options, function(res) {
    console.log(res.statusCode);
    var body = '';
    res.on('data', function(data) {
        body += data;
    });
    res.on('end', function() {
        console.log(body);
    });
    res.on('error', function(error) {
        console.log(error);
    });
});