JAVA客户端通过SOAP与NET的

来源:百度文库 编辑:神马文学网 时间:2024/06/03 16:21:00
package clientServices1.soap1;
import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
public class Soap1 {
public static void main(String[] args) {
String result = "";
try {
String name="Arieslns";
String endpoint = "http://192.168.0.95/SoapSetup/Service.asmx";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("http://tempuri.org/", "Hello"));
call.addParameter("name", org.apache.axis.Constants.XSD_STRING,ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://tempuri.org/Hello");
result = (String)call.invoke(new Object[]{name});
}
catch (Exception e) {
System.err.println(e.toString());
e.printStackTrace();
}
System.out.println(result);
}
}
但是返回值的仅仅是在控制台输出的:Hello!
然后在WebServices方法中添加了:Flie.AppendAllText(@"C:\result.txt",name);
结果生成的文件没有任何内容,参数并没有传递到name变量中……
网友回复:按有几个群,你不妨加进去,可以和大家一起讨论啊.........46986340,28039577,4804620
在那里看看有无能回答你的,谢谢,LZ,甭忘了给俺分哦,谢谢LZ
网友回复:第二种方法的问题解决了,原因出在这一句:
call.addParameter("name", org.apache.axis.Constants.XSD_STRING,ParameterMode.IN);
因为addParameter()的第一个参数没有指定命名空间,所以找不到名为“name”的参数。
这样稍微修改下就可以了:
call.addParameter(new QName("http://tempuri.org/", "name"), org.apache.axis.encoding.XMLType.XSD_STRING,ParameterMode.IN);
成功运行……激动啊……
接下来研究传递复杂的数据类型去……