续http://expert.csdn.net/Expert/topic/2263/2263749.xml?temp=.5426599贴错了,客户端应该是这个
package com.bywang.app;import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.*;
import javax.xml.namespace.QName;
import java.util.*;
import com.bywang.ws.holders.*;
import org.apache.axis.*;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.encoding.Base64;
import org.apache.axis.handlers.BasicHandler;
import org.apache.axis.transport.http.HTTPConstants;
import org.apache.axis.utils.Messages;
import org.apache.axis.message.*;
//import javax.xml.soap.*;
import java.util.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.commons.logging.Log;/**
* This class illustrates how to use the JAX-RPC API to invoke
* the Order Processing Web service dynamically
*/
public class testStringHolderClient {
public static void main(String[] args) throws Exception {
String targetNamespace = "http://generated.myservice.ws.bywang.com";
Service service = new Service(); Call call = (Call) service.createCall();
call.setTargetEndpointAddress("http://localhost:8080/axis/services/testStringHolder");
QName qnstrIn=new QName(targetNamespace,"in0");
QName qnstrInOut=new QName(targetNamespace,"in1");
QName operationName = new QName(targetNamespace, "testStringHolder"); call.setOperationName(operationName);
QName serviceName = new QName(targetNamespace,
"testStringHolder");
call.addParameter("str",qnstrIn,ParameterMode.IN);
call.addParameter("strh",serviceName,ParameterMode.INOUT); call.setReturnType( XMLType.XSD_STRING );
String test=new String("send a test string ");
String inoutStr=new String("send a inout string");
String str=(String)call.invoke( new Object[] {test,inoutStr} );
System.out.println(str);
Map outparams = call.getOutputParams();
if (outparams!=null)
{
Iterator ite=outparams.values().iterator();
if (ite.hasNext())
{
System.out.println((String)ite.next());
}
}
}
}
soap发送消息如下:
xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmln
s:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSc
hema-instance">
<soapenv:Body>
<ns1:testStringHolder soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/e
ncoding/" xmlns:ns1="http://generated.myservice.ws.bywang.com">
<str xsi:type="xsd:string">send a test string </str>
<strh xsi:type="xsd:string">send a inout string</strh>
</ns1:testStringHolder>
</soapenv:Body>
</soapenv:Envelope>
返回消息如下:
xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmln
s:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSc
hema-instance">
<soapenv:Body>
<ns1:testStringHolderResponse soapenv:encodingStyle="http://schemas.xmlsoap.or
g/soap/encoding/" xmlns:ns1="http://generated.myservice.ws.bywang.com">
<testStringHolderReturn xsi:type="xsd:string">return a value</testStringHolde
rReturn>
<strh xsi:type="xsd:string">received string is send a inout string</strh>
</ns1:testStringHolderResponse>
</soapenv:Body>
</soapenv:Envelope>
package com.bywang.app;import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.*;
import javax.xml.namespace.QName;
import java.util.*;
import com.bywang.ws.holders.*;
import org.apache.axis.*;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.encoding.Base64;
import org.apache.axis.handlers.BasicHandler;
import org.apache.axis.transport.http.HTTPConstants;
import org.apache.axis.utils.Messages;
import org.apache.axis.message.*;
//import javax.xml.soap.*;
import java.util.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.commons.logging.Log;/**
* This class illustrates how to use the JAX-RPC API to invoke
* the Order Processing Web service dynamically
*/
public class testStringHolderClient {
public static void main(String[] args) throws Exception {
String targetNamespace = "http://generated.myservice.ws.bywang.com";
Service service = new Service(); Call call = (Call) service.createCall();
call.setTargetEndpointAddress("http://localhost:8080/axis/services/testStringHolder");
QName qnstrIn=new QName(targetNamespace,"in0");
QName qnstrInOut=new QName(targetNamespace,"in1");
QName operationName = new QName(targetNamespace, "testStringHolder"); call.setOperationName(operationName);
QName serviceName = new QName(targetNamespace,
"testStringHolder");
call.addParameter("str",qnstrIn,ParameterMode.IN);
call.addParameter("strh",serviceName,ParameterMode.INOUT); call.setReturnType( XMLType.XSD_STRING );
String test=new String("send a test string ");
String inoutStr=new String("send a inout string");
String str=(String)call.invoke( new Object[] {test,inoutStr} );
System.out.println(str);
Map outparams = call.getOutputParams();
if (outparams!=null)
{
Iterator ite=outparams.values().iterator();
if (ite.hasNext())
{
System.out.println((String)ite.next());
}
}
}
}
soap发送消息如下:
xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmln
s:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSc
hema-instance">
<soapenv:Body>
<ns1:testStringHolder soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/e
ncoding/" xmlns:ns1="http://generated.myservice.ws.bywang.com">
<str xsi:type="xsd:string">send a test string </str>
<strh xsi:type="xsd:string">send a inout string</strh>
</ns1:testStringHolder>
</soapenv:Body>
</soapenv:Envelope>
返回消息如下:
xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmln
s:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSc
hema-instance">
<soapenv:Body>
<ns1:testStringHolderResponse soapenv:encodingStyle="http://schemas.xmlsoap.or
g/soap/encoding/" xmlns:ns1="http://generated.myservice.ws.bywang.com">
<testStringHolderReturn xsi:type="xsd:string">return a value</testStringHolde
rReturn>
<strh xsi:type="xsd:string">received string is send a inout string</strh>
</ns1:testStringHolderResponse>
</soapenv:Body>
</soapenv:Envelope>
解决方案 »
- 新手求救:struts中文问题
- 知道Mondrian的朋友进来看一下啊!
- webwork问题!
- 对于web services调用,如果是C写的程序调用JAVA的程序怎么办呢?
- 关于解析XML的问题
- tomcat 启动 不能解决占位符“host.name”
- 奇怪的Nullpointer Excepton
- 如何在hibernate下使用复合主键,需要注意什么问题,请大家各个小例子作参考好吗?有些着急
- 哪里有可用的rational XDE下载
- 请教如何通过smtp服务器的验证???
- http://www.yffw.com/test9/ 一些资料,特别weblogic中文资料.我刚买的空间:)
- 为什么我部署一个EJB时,总是提示没有部署文件的,应该如何配置!谢谢
因为我试过UTF-8,但是在转换时apache将汉字转成了类似于富这样的东东,真是莫名奇妙
更奇妙的是 富 在google上竟然被正确的认了出来,它是一个"富"字,繁体的.你们可以去试试
只是不知道它是怎么转换的,内码又不像内码
但它将字符转换成类似于富,也是正确的,这是unicode字符表示的。
:)
比如:“富”在GB2312字符集里的偏移是10(这只是假设而已),但在UTF-8里却是100。所以关键在于:你要确保 编码-解码 的字符集是相同或者兼容的。
怪怪,第一次运行,提示
HelloWorldClient.main: Starting test...
HelloWorldClient.main: Error, caught exception: [SOAPException: faultCode=SOAP-E
NV:Client; msg=Error opening socket: java.net.ConnectException: Connection refus
ed: connect; targetException=java.lang.IllegalArgumentException: Error opening s
ocket: java.net.ConnectException: Connection refused: connect]
HelloWorldClient.main: All done!
第二次运行,成功了!!!但是我什么都没有改阿?????连服务器都没重起,只是运行的时间长了一些,怎么回事……耐人寻味……
可以去google上试试,将富输进去,然后搜索,可以看到它正确的认出了这是个“富”字
富
\u5bccchar c = '富';
System.out.println("unicode: " + (int) c); // unicode: 23500
System.out.println("unicode in hex: " + Integer.toHexString((int) c)); // unicode in hex: 5bcc