已编辑
我在ASP.NET Web服务和react-native之间的通信中遇到了一个问题。在阅读以下内容后,我尝试使用 AJAX 请求:最简单的SOAP示例,最后得到错误信息。错误代码如下:
"DONE": 4, "HEADERS_RECEIVED": 2, "LOADING": 3, "OPENED": 1, "UNSENT": 0,
"_aborted": false, "_cachedResponse": undefined, "_hasError": true,
"_headers": {"content-type": "text/xml"},
"_incrementalEvents": false, "_lowerCaseResponseHeaders": {},
"_method": "POST", "_perfKey":
"network_XMLHttpRequest_http://localhost:44358/BikeWebService.asmx",
"_performanceLogger": {"_closed": false, "_extras": {},
"_pointExtras": {}, "_points": {"initializeCore_end": 11271328.84606,
"initializeCore_start": 11271264.66206}, "_timespans":
{"network_XMLHttpRequest_http://localhost:44358/BikeWebService.asmx":
[Object]}}, "_requestId": null, "_response": "Failed to connect to localhost/127.0.0.1:44358",
"_responseType": "", "_sent": true, "_subscriptions": [], "_timedOut": false,
"_trackingName": "unknown", "_url": "http://localhost:44358/BikeWebService.asmx",
"readyState": 4, "responseHeaders": undefined, "status": 0, "timeout": 0, "upload": {}, withCredentials": true
响应本机中 AJAX 请求:
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://localhost:44358/BikeWebService.asmx', true);
var sr ='<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">\
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/LogIn</Action>
</s:Header>
<s:Body>\
<LogIn xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">\
<password>a</password>\
<login>1</login>\
</LogIn>\
</s:Body>\
</s:Envelope>';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
console.log(xmlhttp.responseText);
}
}
console.log(xmlhttp);
}
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
在ASP.NET中,我有一个如下所示的web方法:
[WebMethod]
public ResponseModel<User> LogIn(string password, string login)
{
return new User();
}
我尝试使用axios获取此答案,但仍然出现网络错误。请使用axios向SOAP端点发出请求
我还尝试将cors添加到web.config
,如下所示:How to allow CORS for ASP.NET WebForms endpoint?但还是不行...
SSL在ASP.NET服务中被禁用。我尝试在Windows中禁用防火墙和TLS,但这不是问题,我在ASP.NET 4.8上运行
有人知道吗?XML还好吗?我从WCF测试客户端得到的。
1条答案
按热度按时间68bkxrlz1#
在IIS上启动Web服务并在windos上将地址添加到主机可修复此连接错误。
SOAP请求: