我的axis版本较低是1.1的,
想传递附件 ,wsdd文件怎么配置啊?
<schema targetNamespace="urn:KxItfService">
<import namespace="http://xml.apache.org/xml-soap"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"
/>
<complexType name="AttachFileItem">
<sequence>
<element name="attachFile" nillable="true" type="apachesoap:DataHandler"/>
<element name="fileName" nillable="true" type="soapenc:string"/>
</sequence>
</complexType>
另外,<element name="attachFile" nillable="true" type="apachesoap:DataHandler"/>这一个是如何配置得到的啊?
我的显示是tns1:DataHandler
------解决方案--------------------------------------------------------
service端:
package org.sky.hello;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.activation.DataHandler;
import org.apache.axiom.attachments.Attachments;
import org.apache.axis2.context.MessageContext;
public class AttachmentService {
public String uploadFile(String name, String attchmentID) throws IOException
{
MessageContext msgCtx = MessageContext.getCurrentMessageContext();
Attachments attachment = msgCtx.getAttachmentMap();
DataHandler dataHandler = attachment.getDataHandler(attchmentID);
File file = new File(
name);
FileOutputStream fileOutputStream = new FileOutputStream(file);
dataHandler.writeTo(fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
return "File saved succesfully.";
}
}
service.xml的配置:
<service name="AttachmentService" >
<parameter name="ServiceClass">org.sky.hello.AttachmentService</parameter>
<operation name="uploadFile">
<actionMapping>urn:uploadFile</actionMapping>
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
</service>
要用rpcmessagereceiver
客户端:
package org.sky;
import java.io.File;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.OperationClient;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.wsdl.WSDLConstants;
public class AttachmentClient {
private static EndpointReference targetEPR = new EndpointReference(
"http://127.0.0.1:8080/AxisProject/services/AttachmentService");
public static void main(String[] args) throws Exception {
new AttachmentClient().transferFile();
}
public void transferFile() throws Exception {
String filePath = "d:/test.gif";
String destFile = "d:/Axis2Temp/test.gif";
Options options = new Options();
options.setTo(targetEPR);
options.setProperty(Constants.Configuration.ENABLE_SWA,
Constants.VALUE_TRUE);
options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);