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);
}
}
但是返回值的僅僅是在控制臺(tái)輸出的:Hello!
然后在WebServices方法中添加了:Flie.AppendAllText(@"C:\result.txt",name);
結(jié)果生成的文件沒有任何內(nèi)容,參數(shù)并沒有傳遞到name變量中……
網(wǎng)友回復(fù):按有幾個(gè)群,你不妨加進(jìn)去,可以和大家一起討論啊.........46986340,28039577,4804620
在那里看看有無能回答你的,謝謝,LZ,甭忘了給俺分哦,謝謝LZ
網(wǎng)友回復(fù):第二種方法的問題解決了,原因出在這一句:
call.addParameter("name", org.apache.axis.Constants.XSD_STRING,ParameterMode.IN);
因?yàn)閍ddParameter()的第一個(gè)參數(shù)沒有指定命名空間,所以找不到名為“name”的參數(shù)。
這樣稍微修改下就可以了:
call.addParameter(new QName("http://tempuri.org/", "name"), org.apache.axis.encoding.XMLType.XSD_STRING,ParameterMode.IN);
成功運(yùn)行……激動(dòng)啊……
接下來研究傳遞復(fù)雜的數(shù)據(jù)類型去……
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。