Cordys HTML JS调用 Webservice 解决跨域问题

(1):下载一个 Apache2.2 , 打开httpd.conf ,添加如下代码: 

              Listen 8000 #找到  Apache 默认的端口 ,80  ,修改 80端口 为:8000 

      添加 WebService请求服务器的反向代理:

      ProxyPass /home http://192.168.100.122/home
      ProxyPassReverse /home http://192.168.100.122/home
      ProxyPass /cordys http://192.168.100.122/cordys
      ProxyPassReverse /cordys http://192.168.100.122/cordys


(2):Cordys 模拟登入

     利用Fiddle 抓取模拟登入XML 

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
	<SOAP:Header>
		<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
			<wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
				<wsse:Username>201613</wsse:Username>
				<wsse:Password>201613</wsse:Password>
			</wsse:UsernameToken>
		</wsse:Security>
		<i18n:international xmlns:i18n="http://www.w3.org/2005/09/ws-i18n">
			<locale xmlns="http://www.w3.org/2005/09/ws-i18n">en-US</locale>
		</i18n:international>
	</SOAP:Header>
	<SOAP:Body>
		<samlp:Request xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol" MajorVersion="1" MinorVersion="1" IssueInstant="2015-05-25T03:05:47Z" RequestID="a8636cc371-981e-a06a-8eed-39d1d59b493">
			<samlp:AuthenticationQuery>
				<saml:Subject xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">
					<saml:NameIdentifier Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">201613</saml:NameIdentifier>
				</saml:Subject>
			</samlp:AuthenticationQuery>
		</samlp:Request>
	</SOAP:Body>
</SOAP:Envelope>


获取Response 数据:


var Artifact=$(RXML).find("samlp\\:AssertionArtifact").text();


<samlp:AssertionArtifact xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol">
		MDGr8XizIp4NPSn7RARgH+ZGBjT8LdGnJA7+QOybeSOXxMdpk/IuvAsj
</samlp:AssertionArtifact>

额外知识补充:

How to use SAML artifacts 

模拟登入 验证 成功后:对  AssertionArtifact 进行 encodeURIComponent 然后进行 抓取数据 

完整 代码如下:


<!DOCTYPE html>
<html>
<head lang="zh-CN">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>DEMO—演示SOAP调用</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
</head>
<body>
<div class="container">
    <form class="form-horizontal" role="form">
        <div class="page-header text-left"><h2>输入账户号</h2></div>
            <div class="form-group">
                <div class="row">
                    <label class="col-md-1" for="p_userdn1">租户账户号</label>
                    <div class="col-md-6"><input type="text" id="tenantcount" placeholder="请输入租户账户号" /></div>
                </div>
            </div>
        <div class="form-group">
            <div class="row">
                <button type="button" class="btn btn-primary btn-lg" id="btnLoadUserXML"  >用户XML信息</button>
                <button type="button" class="btn btn-primary btn-lg" id="btnLoadUser" >用户名称</button>
				 <button type="button" class="btn btn-primary btn-lg" id="btnLoadUser" οnclick="">删除Cookie</button>
            </div>
            <div class="row">
                <textarea class="form-control" rows="6"  id="userXML"></textarea>
            </div>
        </div>
    </form>
</div>
<script src="js/jquery-1.11.2.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js"  type="text/javascript"></script>
<script src="js/jquery.cookie.js"  type="text/javascript"></script>
<script type="text/javascript">
var Artifact=null;
$(function(){
	var defaultinst_SAMLart=$.cookie("defaultinst_SAMLart");
	//alert(defaultinst_SAMLart+"encodeURIComponent:" +encodeURIComponent(defaultinst_SAMLart));
	if(defaultinst_SAMLart==""||defaultinst_SAMLart==undefined){
		VLogin();	
	}
    $("#btnLoadUserXML").click(loadUserXML);
	

});

 function VLogin(){
	var gwUrl="http://192.168.100.108:8000/home/comac/com.eibus.web.soap.Gateway.wcp";
	var lgXML="<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">"
				+"<SOAP:Header>"
					+"<wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
						+"<wsse:UsernameToken xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
							+"<wsse:Username>201613</wsse:Username>"
							+"<wsse:Password>201613</wsse:Password>"
						+"</wsse:UsernameToken>"
					+"</wsse:Security>"
					+"<i18n:international xmlns:i18n=\"http://www.w3.org/2005/09/ws-i18n\">"
						+"<locale xmlns=\"http://www.w3.org/2005/09/ws-i18n\">en-US</locale>"
					+"</i18n:international>"
				+"</SOAP:Header>"
				+"<SOAP:Body>"
					+"<samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" MajorVersion=\"1\" MinorVersion=\"1\" IssueInstant=\"2015-05-21T05:57:42Z\" RequestID=\"a24de77846-7113-0716-468d-54a740939ce\">"
						+"<samlp:AuthenticationQuery>"
							+"<saml:Subject xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\">"
								+"<saml:NameIdentifier Format=\"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified\">201613</saml:NameIdentifier>"
							+"</saml:Subject>"
						+"</samlp:AuthenticationQuery>"
					+"</samlp:Request>"
				+"</SOAP:Body>"
				+"</SOAP:Envelope>";
	$.ajax(
				{url:gwUrl,
				type:"POST",
				dataType:"xml",
				data: lgXML,
				contentType:"text/xml; charset=\"utf-8\"",
				complete:lgResult
	   }
);
return false;

}

 function lgResult(result, status){
	var RXML=result.responseText;
	Artifact=$(RXML).find("samlp\\:AssertionArtifact").text();
}




function loadUserXML(){
	var gwUrl="http://192.168.100.108:8000/home/comac/com.eibus.web.soap.Gateway.wcp";
		
	var dUrl = "http://192.168.100.108:8000/home/comac/com.eibus.web.soap.Gateway.wcp" 

	dUrl=dUrl+"?SAMLart="+encodeURIComponent(Artifact);		

	var dXML  ="<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">"
				+"<SOAP:Body>"
				+"<GetDepartmentByParentID xmlns=\"http://schemas.cordys.com/CommonPackage\" preserveSpace=\"no\" qAccess=\"0\" qValues=\"\">"
				+"<ParentID>29</ParentID>"
				+"</GetDepartmentByParentID>"
				+"</SOAP:Body>"
				+"</SOAP:Envelope>";

	
	$.ajax(
		{url:dUrl,
		type:"POST",
		dataType:"xml",
		data: dXML,
		contentType:"text/xml; charset=\"utf-8\"",
		complete:getResult
	}
	);
	return false;
}
    

function getResult(result, status){
	
	$("#userXML").val(result.responseText);  
}


$(function(){
    $("#btnLoadUser").click(getUserName);
});


function getUserName(){
var v_userXML = $("#userXML").val();

$("#userXML").val($(v_userXML).find("department>DepartName").text());
}
</script>
</body>
</html>





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值