我使用node-soap请求SOAP-API。但是结果却不是我所期望的。 如果我使用PHP请求相同的请求,它将按预期工作(所有api示例都在php中)。 但是我的应用程序/服务是用JavaScript(ExpressJS)编写的。
我的请求代码非常简单:
public async Task<IActionResult> Edit(int id,
[Bind("RouteStopId,BusRouteCode,BusStopNumber,OffsetMinutes")]
RouteStop
routeStop)
{
if (id != routeStop.RouteStopId)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
_context.Update(routeStop);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!RouteStopExists(routeStop.RouteStopId))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
ViewData["BusRouteCode"] = new SelectList(_context.BusRoute,
"BusRouteCode", "BusRouteCode", routeStop.BusRouteCode);
ViewData["BusStopNumber"] = new SelectList(_context.BusStop,
"BusStopNumber", "BusStopNumber", routeStop.BusStopNumber);
return View(routeStop);
CLubs (Edit):-
if (id != club.ClubId)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
_context.Update(club);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ClubExists(club.ClubId))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
ViewData["StyleCode"] = new SelectList(_context.Style,
"StyleCode",
"StyleCode", club.StyleCode);
return View(club);
}
结果如下:
var url = '...wsdl';
var args = {
Params: JSON.stringify({
User: '...',
AuthType: 'session',
AuthData: '...',
RequestType: 'get_mailaccounts',
RequestParams: []
})
};
soap.createClient(url, function(err, client) {
client.Api(args, function(err, result, rawResponse, soapHeader, rawRequest) {
console.log(util.inspect(result, {showHidden: false, depth: null}));
});
});
该对象包含的信息可以,并且可以预期。但是为什么嵌套这么奇怪呢?我从上述PHP代码获得的结果对象如下所示:
{
"return": {
"attributes": {
"xsi:type": "ns2:Map"
},
"item": [
{
"key": {
"$value": "Request",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"attributes": {
"xsi:type": "ns2:Map"
},
"item": [
{
"key": {
"$value": "RequestTime",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "1540823916",
"attributes": {
"xsi:type": "xsd:int"
}
}
},
{
"key": {
"$value": "RequestType",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "get_mailaccounts",
"attributes": {
"xsi:type": "xsd:string"
}
}
},
{
"key": {
"$value": "RequestParams",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"attributes": {
"SOAP-ENC:arrayType": "xsd:ur-type[0]",
"xsi:type": "SOAP-ENC:Array"
}
}
}
]
}
},
{
"key": {
"$value": "Response",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"attributes": {
"xsi:type": "ns2:Map"
},
"item": [
{
"key": {
"$value": "FloodDelay",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "0.5",
"attributes": {
"xsi:type": "xsd:float"
}
}
},
{
"key": {
"$value": "ReturnString",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "TRUE",
"attributes": {
"xsi:type": "xsd:string"
}
}
},
{
"key": {
"$value": "ReturnInfo",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"attributes": {
"SOAP-ENC:arrayType": "ns2:Map[1]",
"xsi:type": "SOAP-ENC:Array"
},
"item": {
"attributes": {
"xsi:type": "ns2:Map"
},
"item": [
{
"key": {
"$value": "mail_login",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "xxxxxxx",
"attributes": {
"xsi:type": "xsd:string"
}
}
},
{
"key": {
"$value": "mail_password",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "xxxxxxx",
"attributes": {
"xsi:type": "xsd:string"
}
}
},
{
"key": {
"$value": "mail_adresses",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "xx@xx.de",
"attributes": {
"xsi:type": "xsd:string"
}
}
},
]
}
}
}
]
}
}
]
}
}
这就是我想要的。