js调用webservice的问题~~~~

amingo amingo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
js:
function getXMLHTTPRequest()
{
var xRequest = null;
if( window.XMLHttpRequest )
{
xRequest = new XMLHttpRequest(); // Mozilla and Safari
}
else if( typeof ActiveXObject != "undefined" )
{
xRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
return xRequest;
}

function getWebService()
{
var request = getXMLHTTPRequest();

request.open("post", "http://localhost/webservice1/service1.asmx", false);

request.SetRequestHeader ("Content-Type","text/xml; charset=utf-8");
request.SetRequestHeader ("SOAPAction","http://tempuri.org/HelloWorld");

var data;
data = ' <?xml version="1.0" encoding="utf-8"?>';
data = data + ' <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
data = data + ' <soap:Body>';
data = data + ' <HelloWorld xmlns="http://tempuri.org/">';
data = data + ' <name>123 </name>';
data = data + ' </HelloWorld>';
data = data + ' </soap:Body>';
data = data + ' </soap:Envelope>';

request.onreadystatechange=function()
{
if (request.readyState==4)
{
if(request.status ==200)
{
alert( request.responseText);
}
}
}
request.send(data);

}


vb.net:
<WebMethod()> _
Public Function HelloWorld(ByVal name As String) As String
Return name
End Function

<web.config>中也进行了配置

执行getWebService()后报错了,System.Web.Services.Protocols.SoapException: 服务器未能识别 HTTP 标头 SOAPAction 的值:http://tempuri.org/HelloWorld。
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
不知如何解决??

另外这种调用方式是post还是SOAP,我觉得应该是SOAP,那么post方式是如何调用?

一般帖子,请勿使用“版主进”之类的字眼,谢谢合作
by 竹子版主
...全文

相关推荐

评论 35
收藏 已收藏
分享
返回顶部
amingo
.NET社区 62,271 成员 668,968 内容