axis 用附件发文件问题
大家帮我找找看 看看我的程序有什么错误 我怎么得不到文件啊
server 端
import java.io.*;
import javax.activation.*;
import javax.activation.DataSource;
public class SendFile {
public DataHandler sendFile(String fname) {
System.out.printf(fname);
DataHandler ret = null;
try {
//java.io.File file = new java.io.File(filepath);
//if (file.isFile() && file.canRead()) {
//String fname = file.getAbsoluteFile().getCanonicalPath();
ret= new DataHandler(new FileDataSource(fname));
// ret = new DataHandler(ds);
//}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return ret;
}
}
client 端
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.XMLType;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;
import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;
public class SentFile {
public static void main(String[] args) {
try {
//DataHandler dhSource = new DataHandler(new FileDataSource(""));
String endpoint = "http://localhost:8080/axis/SendFile.jws";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("SendFile", "sendFile"));
QName qnameAttachment = new QName("SendFile", "DataHandler");
call.registerTypeMapping(DataHandler.class, qnameAttachment,
JAFDataHandlerSerializerFactory.class,
JAFDataHandlerDeserializerFactory.class);
call.addParameter("fname", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(qnameAttachment);
DataHandler ret = (DataHandler) call.invoke(new Object[] {"C:\\1.bmp"});
//System.out.printf(ret.getName());
java.io.File receivedFile = new java.io.File("d:\\" + ret.getName()); // 文件生成
} catch (Exception ex) {
ex.printStackTrace();
}
}
}