Java论坛网»Java技术»JAVA 调用 .NET写的WEB SERVICE的问题(包括无法传递参数,SOAP头验证)
JAVA 调用 .NET写的WEB SERVICE的问题(包括无法传递参数,SOAP头验证)
问?:
//AXIS 代码
try {
String i = "440303";
String endpoint=TestNetService.url;//根据初始化的配置参数而来
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("http://fmmis/service/",TestNetService.mothed)); //根据初始化的配置参数而来
//call.setOperationName( TestNetService.mothed );
//设置入口参数
call.addParameter("areacode",XMLType.XSD_STRING, ParameterMode.IN );
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI(TestNetService.namespace+TestNetService.mothed);//命名空间.
String result = (String)call.invoke(new Object[]{i});
System.out.println(result);
}
catch (Exception e) {System.err.println(e.toString());}
//对方WEB SERVICE 方法
StrGetEpCode
获取企业统一编码信息,其中区域编码参数areacode的范围为[440303,440304,440305,440306,440307,440308]
测试
测试窗体只能用于来自本地计算机的请求。
SOAP
下面是一个 SOAP 请求和响应示例。所显示的占位符需要由实际值替换。
POST /FMMIS/services/FmmisServices.asmx HTTP/1.1
Host: 203.175.136.223
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://fmmis/service/StrGetEpCode"
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Header>
<FmmisSoapHeader xmlns="http://fmmis/service">
<UserName>string</UserName>
<Password>string</Password>
<SHAContext>string</SHAContext>
</FmmisSoapHeader>
</soap:Header>
<soap:Body>
<StrGetEpCode xmlns="http://fmmis/service">
<areacode>string</areacode>
</StrGetEpCode>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<StrGetEpCodeResponse xmlns="http://fmmis/service">
<StrGetEpCodeResult>string</StrGetEpCodeResult>
</StrGetEpCodeResponse>
</soap:Body>
</soap:Envelope>
上面的代码调用时,如何给对方的SOAP头传递身份验证的参数?
另,去掉SOAP头的身份验证,本身调用的方法也无法传递参数过去,服务器端接受到的SOAP包可以见到有440303,但解析出来的都是null。
请给出解决的代码。
try {
String i = "440303";
String endpoint=TestNetService.url;//根据初始化的配置参数而来
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("http://fmmis/service/",TestNetService.mothed)); //根据初始化的配置参数而来
//call.setOperationName( TestNetService.mothed );
//设置入口参数
call.addParameter("areacode",XMLType.XSD_STRING, ParameterMode.IN );
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI(TestNetService.namespace+TestNetService.mothed);//命名空间.
String result = (String)call.invoke(new Object[]{i});
System.out.println(result);
}
catch (Exception e) {System.err.println(e.toString());}
//对方WEB SERVICE 方法
StrGetEpCode
获取企业统一编码信息,其中区域编码参数areacode的范围为[440303,440304,440305,440306,440307,440308]
测试
测试窗体只能用于来自本地计算机的请求。
SOAP
下面是一个 SOAP 请求和响应示例。所显示的占位符需要由实际值替换。
POST /FMMIS/services/FmmisServices.asmx HTTP/1.1
Host: 203.175.136.223
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://fmmis/service/StrGetEpCode"
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Header>
<FmmisSoapHeader xmlns="http://fmmis/service">
<UserName>string</UserName>
<Password>string</Password>
<SHAContext>string</SHAContext>
</FmmisSoapHeader>
</soap:Header>
<soap:Body>
<StrGetEpCode xmlns="http://fmmis/service">
<areacode>string</areacode>
</StrGetEpCode>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<StrGetEpCodeResponse xmlns="http://fmmis/service">
<StrGetEpCodeResult>string</StrGetEpCodeResult>
</StrGetEpCodeResponse>
</soap:Body>
</soap:Envelope>
上面的代码调用时,如何给对方的SOAP头传递身份验证的参数?
另,去掉SOAP头的身份验证,本身调用的方法也无法传递参数过去,服务器端接受到的SOAP包可以见到有440303,但解析出来的都是null。
请给出解决的代码。
答!: 1:
“测试窗体只能用于来自本地计算机的请求。”
注意DNS的问题
注意DNS的问题
答!: 2:
检查过了,DNS并无问题,只要服务器端的SOAP头验证去掉,客户端再调用一些不需要传递参数的方法,是可以正常返回值的。
这里主要有两个问题:
1:如何修改、设置传递给服务器端的SOAP头内容(加上身份验证信息)
2:客户端调用方法时,传递参数问题。服务器端是可以接收到的(已验证SOAP包),但无法解析该传递过去的值,因此变成了null。
请高手再次指点。
这里主要有两个问题:
1:如何修改、设置传递给服务器端的SOAP头内容(加上身份验证信息)
2:客户端调用方法时,传递参数问题。服务器端是可以接收到的(已验证SOAP包),但无法解析该传递过去的值,因此变成了null。
请高手再次指点。
答!: 3:
问题仍未解决,请高手帮帮忙!!
答!: 4:
现SOAP头的问题已解决,代码如下,另参数问题请高手赐教,分不够再给,狂给,定不失信
SOAPHeaderElement soapHeaderElement,soapHeaderElement2;
soapHeaderElement = new SOAPHeaderElement(namespace, "FmmisSoapHeader");
soapHeaderElement.setNamespaceURI(namespace);
soapHeaderElement.addChildElement("UserName").setValue("xxx");
soapHeaderElement.addChildElement("Password").setValue("xxx");
soapHeaderElement.addChildElement("SHAContext").setValue("xxx");
call.addHeader(soapHeaderElement);
SOAPHeaderElement soapHeaderElement,soapHeaderElement2;
soapHeaderElement = new SOAPHeaderElement(namespace, "FmmisSoapHeader");
soapHeaderElement.setNamespaceURI(namespace);
soapHeaderElement.addChildElement("UserName").setValue("xxx");
soapHeaderElement.addChildElement("Password").setValue("xxx");
soapHeaderElement.addChildElement("SHAContext").setValue("xxx");
call.addHeader(soapHeaderElement);
相关JAVA教程:
这是什么错误啊
Jsp excel 乱码 问题
应该学习.net还是java
hibernate 多对多关连
请问如何设计可即插即用的swt界面
weblogic9怎么配置连接池
关于判断是否为空格
opensso
J2EE框架中多个WEB模块的授权问题
数据库无法加入信息
哪位能够告诉我tapestry的运行机制阿!!!!!
struts的路径问题,高手帮忙