JS调用带密码验证的Webservice

基于之前知识:webservice就是约定提交和返回数据格式的http请求。那个不仅可以用DotNetCore的HttpClient调用带密码的webservice,用js也能请求webservice。

JS代码

CallWebservice("http://127.0.0.1:57772/imedicallis/csp/LIS.WS.DHCLISService.cls", "_system", "SYS", "Service.LIS.QC.DHCQCService","GetMachineList","","");
            //调用webservice
            function CallWebservice(Address, UserName, UserPass, ClassName, FuncName, Param, Session)
            {
                var xml = '<?xml version="1.0" encoding="utf-8"?>';
                xml += '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">';
                xml += '<soap:Header>';
                xml += '<wsa:Action>http://tempuri.org/LIS.WS.DHCLISService.GetData</wsa:Action>';
                xml += '<wsa:ReplyTo>';
                xml += '<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>';
                xml += '</wsa:ReplyTo>';
                xml += '<wsa:To>' + Address + '</wsa: To >';
                xml += '<wsse:Security soap:mustUnderstand="1">';
                xml += '<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-29db7c92-1098-4717-b7fb-aac473632fec">';
                xml += '<wsse:Username>' + UserName + '</wsse:Username>';
                xml += '<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' + UserPass + '</wsse:Password>';
                xml += '</wsse:UsernameToken>';
                xml += '</wsse:Security>';
                xml += '</soap:Header>';
                xml += '<soap:Body>';
                xml += '<GetData xmlns ="http://tempuri.org">';
                xml += '<ClassName>" + ClassName + "</ClassName>';
                xml += '<FuncName >" + FuncName + "</FuncName>';
                xml += '<Param ><![CDATA[" + Param + "]]></Param>';
                xml += '<Session >' + Session + '</Session>';
                xml += '</GetData >';
                xml += '</soap:Body>';
                xml += '</soap:Envelope>';
                $.ajax({
                    headers: { SOAPAction: 'http://tempuri.org/LIS.WS.DHCLISService.GetData' },
                    contentType: 'application/soap+xml;charset=UTF-8;action="http://tempuri.org/LIS.WS.DHCLISService.GetData"',
                    dataType: 'xml',
                    type: 'post',
                    crossDomain: true,
                    xhrFields: {
                        withCredentials: true
                    },
                    url: Address,
                    data: xml,
                    success: function (data) {
                        var ss = $(data).find("GetDataResult").first().text();
                        alert(ss);
                    }
                });
            }

webservice输出允许跨域的头,也能用js调用带密码验证的webservice

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小乌鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值