ATLServer WebService调用???

jxb_memory 2012-03-20 10:08:56
我现在使用VC的ATL Server创建的WebService,但是现在在js中怎么也无法调用成功,如下:
<html>
<head>
<title>My WebService Test</title>
</head>
<script language="javascript" type="text/javascript">
// <!CDATA[
  
//define
var xmlhttp;
var value=new Array();
var variable=new Array();
  
//Show Response MSG.
function handleStateChange()
{
  var h=document.getElementById("Label1");
  if(xmlhttp.readyState==4)
  {
alert(xmlhttp.status);
    if(xmlhttp.status==200)
    {
      alert(xmlhttp.responseText);
      h.innerHTML=xmlhttp.responseText;
      //h.innerHTML=xmlhttp.responseXML;
    }
    else if(xmlhttp.status==404)
    {
      h.innerHTML="<br>找不到请求的服务器资源!";
    }
  }
  else if(xmlhttp.readyState==0)
  {
    h.innerHTML="<br>未初始化!";
  }
  else if(xmlhttp.readyState==1)
  {
    h.innerHTML="<br>正在加载……!";
  }
  else if(xmlhttp.readyState==2)
  {
    h.innerHTML="<br>已经加载完成!";
  }
  else if(xmlhttp.readyState==3)
  {
    h.innerHTML="<br>正在和服务器交互";
  }
  else
  {
    h.innerHTML=xmlhttp.responseXML;
  }
  
}
  
//Get Request Data's length
function getlen(str)
{
var bytesCount=0;
for (var i = 0; i < str.length; i++)
{
var c = str.charAt(i);
if (/^[u0000-u00ff]$/.test(c))  //匹配双字节
   {
bytesCount += 1;
}
else
{
bytesCount += 2;
}
}
return bytesCount;
  
} 
  
//Create XMLHttpRequest Object
 function createXMLHttpRequest()
{
  
  if(window.ActiveXObject)
  {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if(window.XMLHttpRequst)
  {
    xmlhttp=new XMLHttpRequest();
  }
} 
  
//send Request By HTTP POST
  
function RequestByPost(method,variable,value,url,_Namespace)
{
createXMLHttpRequest();
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 + '<'+method+' xmlns="'+_Namespace+'">';
for(var i=0;i<variable.length;i++)
{
  data = data + '<'+variable[i]+'>'+value[i]+'</'+variable[i]+'>';
  
}
data = data + '</'+method+'>';
data = data + '</soap:Body>';
data = data + '</soap:Envelope>';
  
xmlhttp.onreadystatechange=handleStateChange;
xmlhttp.Open("POST",url, true);
xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=utf-8");
xmlhttp.SetRequestHeader ("Content-Length",getlen(data));
xmlhttp.SetRequestHeader ("SOAPAction",_Namespace+method);
xmlhttp.Send(data);
alert(data);
}
  
//CallHelloWorld!
function SayHello_onclick() {
//alert(document.getElementById('YourName').value);
a=new Array();
a.push("HelloWorldIn");
a.push("HelloWorldOut");
b=new Array();
b.push("jxb3");
b.push("jxb4");
//此处到底应该如何写才能获取到输出参数的值?
//目前返回的是WSDL文件HelloWorld函数根本没响应?

RequestByPost("HelloWorld",a,b,"http://127.0.0.1/TestWebService/TestWebService.dll?Handler=GenTestWebServiceWSDL","http://localhost/");
}
}
  
// ]]>
</script>

<body>

<p><input type="button" value="Say "Hello world"" onclick="SayHello_onclick();" /></p>

<div id="Label1">test</div>
</body>
</html>
那位做过的能指点一二?????
...全文
99 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxb_memory 2012-03-20
  • 打赏
  • 举报
回复
我自己搞定了!!!

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧