续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>

解决方案 »

  1.   

    应该不会吧,UTF-8完全支持汉字啊.
      

  2.   

    我觉得和UTF-8无关
    因为我试过UTF-8,但是在转换时apache将汉字转成了类似于&#23500;这样的东东,真是莫名奇妙
    更奇妙的是 &#23500; 在google上竟然被正确的认了出来,它是一个"富"字,繁体的.你们可以去试试
    只是不知道它是怎么转换的,内码又不像内码
      

  3.   

    跟中间过程无关。那是你两端的编码方式不匹配导致的。你查一下客户端发送时的编码是什么?确保使用的是soap的编码。
      

  4.   

    如果服务器是axis配置的就不会有问题的。如果是其它的,很难说啦。Axis 1.1时将编码转化为UTF-8的条件是字符串中不含有保留字符(引号,<,>等等)
    但它将字符转换成类似于&#23500,也是正确的,这是unicode字符表示的。
      

  5.   

    呵呵,还有一点,Axis在传输字符时不能传输"\x02"等等,内码为1~8的字符
    :)
      

  6.   

    我想知道的就是它是怎样将"富"转换成&#23500的?
      

  7.   

    如果知道了这个转换方法,那我们完全可以写自已的SOAP Client的部件了
      

  8.   

    使用的字符集不同,同一个位置多代表的字符就不一样,当然其内码也就不一样。
    比如:“富”在GB2312字符集里的偏移是10(这只是假设而已),但在UTF-8里却是100。所以关键在于:你要确保 编码-解码 的字符集是相同或者兼容的。
      

  9.   

    说到 汉字 传输的问题,我从没试验过,于是好奇试了一试。
    怪怪,第一次运行,提示
    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!
    第二次运行,成功了!!!但是我什么都没有改阿?????连服务器都没重起,只是运行的时间长了一些,怎么回事……耐人寻味……
      

  10.   

    因为已经知道,汉字被编码为了类似于&#23500的东西然后送到服务器,服务器又能做正确的处理,而直接传送汉字却不行,所以,我们现在只要知道汉字是怎么被转成&#23500这种样子的就行了。
    可以去google上试试,将&#23500输进去,然后搜索,可以看到它正确的认出了这是个“富”字
      

  11.   

    C:\>native2ascii

    \u5bccchar c = '富';
    System.out.println("unicode: " + (int) c); // unicode: 23500
    System.out.println("unicode in hex: " + Integer.toHexString((int) c)); // unicode in hex: 5bcc