JAVA调用WEB SERVICE里遇到一个难题 100
在用JAVA调用WEBSERVICE里遇到一个难题,下面是代码:packagecom.test;importjava.net.*;importjava.util.Vect...
在用JAVA调用WEB SERVICE里遇到一个难题,下面是代码:
package com.test;
import java.net.*;
import java.util.Vector;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.encoding.SOAPMappingRegistry;
import org.apache.soap.encoding.soapenc.StringDeserializer;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
import org.apache.soap.transport.http.SOAPHTTPConnection;
import org.apache.soap.util.xml.QName;
import org.apache.commons.codec.binary.Base64;
public class WsTest {
public static void main(String[] args) throws Exception,SOAPException {
URL url = null;
try {
url=new URL("http://1921.168.102.27:8080/sjpt-sjptEJB/DrugInterfacesImpl");
} catch (MalformedURLException mue) {
System.err.println( mue.getMessage());
}
Call soapCall = new Call();
soapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
soapCall.setTargetObjectURI("urn:DirectoryInterfaceService" );
soapCall.setMethodName("testClient");
Vector soapParams = new Vector();
// name, type, value, encoding style
Parameter clientId = new Parameter("clientId", int.class,"13641", null);
String no="79508032-2";
String baseno = new String(Base64.encodeBase64(no.getBytes("UTF-8")));//加密//Nzk1MDgwMzItMg==
Parameter centerNo = new Parameter("centerNo", String.class,no,null);//79508032-2
soapParams.addElement(clientId);
soapParams.addElement(centerNo);
soapCall.setParams(soapParams);
soapCall.setEncodingStyleURI("http://www.w3.org/2001/XMLSchema");
try {
Response soapResponse = soapCall.invoke(url,"");
if (soapResponse.generatedFault()) {
Fault fault = soapResponse.getFault();
String returnstr = fault.getFaultString();
System.out.println("返回加密信息: " + returnstr);
byte[] encodeBase64 = Base64.decodeBase64(returnstr.getBytes("UTF-8"));
System.out.println("返回信息: " + new String(encodeBase64));
} else {
Parameter soapResult = soapResponse.getReturnValue ();
System.err.println( soapResult.getValue().toString());
}
} catch (SOAPException se) {
System.err.println( se.getMessage());
}
}
}
返回的错误信息:
No Serializer found to serialize a 'org.apache.soap.rpc.Parameter' using encoding style 'http://www.w3.org/2001/XMLSchema'.
问题好像是返回的信息没有序列化,JAVA没有对应的类型,不能接收。 展开
package com.test;
import java.net.*;
import java.util.Vector;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.encoding.SOAPMappingRegistry;
import org.apache.soap.encoding.soapenc.StringDeserializer;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
import org.apache.soap.transport.http.SOAPHTTPConnection;
import org.apache.soap.util.xml.QName;
import org.apache.commons.codec.binary.Base64;
public class WsTest {
public static void main(String[] args) throws Exception,SOAPException {
URL url = null;
try {
url=new URL("http://1921.168.102.27:8080/sjpt-sjptEJB/DrugInterfacesImpl");
} catch (MalformedURLException mue) {
System.err.println( mue.getMessage());
}
Call soapCall = new Call();
soapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
soapCall.setTargetObjectURI("urn:DirectoryInterfaceService" );
soapCall.setMethodName("testClient");
Vector soapParams = new Vector();
// name, type, value, encoding style
Parameter clientId = new Parameter("clientId", int.class,"13641", null);
String no="79508032-2";
String baseno = new String(Base64.encodeBase64(no.getBytes("UTF-8")));//加密//Nzk1MDgwMzItMg==
Parameter centerNo = new Parameter("centerNo", String.class,no,null);//79508032-2
soapParams.addElement(clientId);
soapParams.addElement(centerNo);
soapCall.setParams(soapParams);
soapCall.setEncodingStyleURI("http://www.w3.org/2001/XMLSchema");
try {
Response soapResponse = soapCall.invoke(url,"");
if (soapResponse.generatedFault()) {
Fault fault = soapResponse.getFault();
String returnstr = fault.getFaultString();
System.out.println("返回加密信息: " + returnstr);
byte[] encodeBase64 = Base64.decodeBase64(returnstr.getBytes("UTF-8"));
System.out.println("返回信息: " + new String(encodeBase64));
} else {
Parameter soapResult = soapResponse.getReturnValue ();
System.err.println( soapResult.getValue().toString());
}
} catch (SOAPException se) {
System.err.println( se.getMessage());
}
}
}
返回的错误信息:
No Serializer found to serialize a 'org.apache.soap.rpc.Parameter' using encoding style 'http://www.w3.org/2001/XMLSchema'.
问题好像是返回的信息没有序列化,JAVA没有对应的类型,不能接收。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询