我在服务器端的类:
import org.jdom.;
import org.jdom.output.;
import org.jdom.Attribute.;
import org.jdom.input.;
import java.io.*;
public class MyService
{
public Document serviceMethod (String arg)throws Exception
{
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(new FileInputStream("exampleA.xml"));
return doc;
}
}
client端的类:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;
import org.jdom.*;
import org.jdom.output.;
import org.jdom.Attribute.;
import org.jdom.input.*;
import java.io.*;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
public class Client
{
public static void main(String [] args) throws Exception
{
try {
String endpointURL ;
//endpointURL="http://localhost:1234/axis/services/MyService";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress("http://localhost:1234/axis/services/MyService");
call.setOperationName( "serviceMethod" );
//call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );
Document doc = (Document) call.invoke( new Object[] { "textToSend" } );
String indent = " ";
boolean newLines = true;
XMLOutputter outp = new XMLOutputter(indent,newLines,"GBK");
outp.output(doc, new FileOutputStream("exampleB.xml"));
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
运行client端的程序后,报告(500)Internal Server Error
请问我该怎么才能返回一个Document类呢?
---------------------------------------------------------------
对了,我就是这个意思:)
public synchronized void signIn (Envelope env, SOAPContext reqCtx, SOAPContext resCtx)
throws MessagingException,IOException
{
//parse soap body
parseBody(env);
//verify
int r=sign(username,pwd,dataset);
resultString="
1<response>" + Integer.toString(r) +"</response>
";
resCtx.setRootPart(resultString,"text/xml;charset=utf-8");
}
setRootPart不是JDOM的方法,而是SOAPContext的方法,具体可以看apache soap的api
这个方法的第一个参数就是要返回的string值。
用下面的就可以接受返回过来的值了。
// receive whatever from the transport and dump it to the screen
SOAPTransport st = msg.getSOAPTransport ();
BufferedReader br = st.receive ();
//SOAPContext sc=st.getResponseSOAPContext();
//sc.writeTo(System.out);
String s;
String str="";
while((s=br.readLine())!=null)
{
str+=s+"\n";
}
jTextArea2.setText(str);