当前位置: 代码迷 >> Web Service >> webService下传数据时服务器取到的数据不完整
  详细解决方案

webService下传数据时服务器取到的数据不完整

热度:307   发布时间:2016-05-02 02:47:59.0
webService上传数据时服务器取到的数据不完整。
客户端

package cn.flyingsoft.oais.service.webService.client;
import java.io.File;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMText;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

public class LineFileInteropServiceStub1 {

private static EndpointReference targetEPR =new EndpointReference("http://127.0.0.1:8080/esoaisapp/services/LineFileInteropService");  
 
public static OMElement getMethod(DataHandler dh,String filePath,String fileName,String fileType) {  
OMFactory fac = OMAbstractFactory.getOMFactory();  
OMNamespace omNs = fac.createOMNamespace("http://webService.service.oais.flyingsoft.cn", "tns");  
 
OMElement method = fac.createOMElement("lineFileUpload", omNs);
 
OMElement value1 = fac.createOMElement("dh", omNs);
OMElement value2= fac.createOMElement("fileContent", omNs);
OMElement value3 = fac.createOMElement("fileName", omNs);
OMElement value4 = fac.createOMElement("fileType", omNs);
 
value1.addChild(fac.createOMText(dh, true));  
value2.addChild(fac.createOMText(value2, filePath));  
value3.addChild(fac.createOMText(value3, fileName));  
value4.addChild(fac.createOMText(value4, fileType));  

method.addChild(value2);  
method.addChild(value3);  
method.addChild(value4);
method.addChild(value1); 
 
return method;  
}  
 
public static void main(String[] args) {  
try {  
String filePath="d:/2012-09-24 13-23-05.zip";
String fileName="2012-09-24 13-23-05";
String fileType="zip";
DataHandler dh = new DataHandler(new FileDataSource(filePath)); // ftpPath为 服务器名+虚拟路径
OMElement authentication = getMethod(dh,filePath,fileName,fileType);  
System.out.println(authentication);
Options options = new Options();  
options.setTo(targetEPR);  
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);  
org.apache.axis2.client.ServiceClient sender = new org.apache.axis2.client.ServiceClient();  
sender.setOptions(options);  
OMElement result = sender.sendReceive(authentication); //调用服务 返回result
OMElement returnEle = result.getFirstElement();
System.out.println(returnEle.getText()) ;
} catch (Exception e) {  
e.printStackTrace();  
}  
}  


}
服务器
package cn.flyingsoft.oais.service.webService;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;


import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
  相关解决方案