JavaScript Soap 方式调用WebService

//JavaScript 通过Soap 调用WebService 
function SendSMSByWebService(){
var data;
var UserName="web服务用户名";
var PassWord="密码";
var strMobilePhone=document.getElementById("txtMobilePhone").value;
var strUserName=document.getElementById("txtUserName").value;
var UserPwd=document.getElementById("ChangePwd").value;
var strContent="用户:"+strUserName+"您好,您的产品密码为"+UserPwd+",请妥善保管。如有问题请致电开来客服部:";
var MobileReg=/^(13+\d{9})|(159+\d{8})|(153+\d{8})$/;
var strYDKey="密匙"
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:Header>';
data = data + '<CredentialSoapHeader xmlns="http://www.cnsec.com/">' ;
data = data + '<UserName>'+UserName+'</UserName>' ;
data = data + '<PassWord>'+PassWord+'</PassWord>' ;
data = data + '</CredentialSoapHeader>';
data = data + '</soap:Header>';
data = data + '<soap:Body>';
data = data + '<WebCntSendSmsSP xmlns="http://www.cnsec.com/">';
data = data + '<strMobilePhone>'+strMobilePhone+'</strMobilePhone>';
data = data + '<strYDKey>'+strYDKey+'</strYDKey>';
data = data + '<strContent>'+strContent+'</strContent>';
data = data + '</WebCntSendSmsSP>';
data = data + '</soap:Body>';
data = data + '</soap:Envelope>';
var url="http://"+ipaddress+"/LogonWS.asmx";
if(strMobilePhone==""){
alert("用户手机号码为空,请填写正确的用户手机号码在发送密码!");
document.getElementById("txtMobilePhone").focus();
return false;
}else if(!MobileReg.test(strMobilePhone)){
alert("请填写正确的手机号码在发送密码!");
document.getElementById("txtMobilePhone").focus();
return false;
}else{
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("post",url,false);
xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=utf-8");
xmlhttp.SetRequestHeader ("Content-Length",data.length);
xmlhttp.SetRequestHeader ("host",ipaddress);
xmlhttp.SetRequestHeader ("SOAPAction", "http://www.cnsec.com/WebCntSendSmsSP");
xmlhttp.send(data);
var x = xmlhttp.responseXML;
var temp=x.childNodes[1].text;//返回值
if (temp==1){
alert("发送短信成功!");
}else{
alert("发送短信失败,请联系管理员!错误码:"+temp);
}
}
}

 

posted @ 2011-12-01 11:37  晓风拂月  阅读(2053)  评论(0编辑  收藏  举报