我寫了一個很簡單的功能
就是呼叫sayHelloWorld這個function時
回傳HelloWorld
然後印出來
我把這個class放在soap admin上
奇怪的是
在傳遞SOAP時
看不到它的SOAP header部分(被省略了)
因為程式還算初學
所以不知道要怎麼改
才會讓它顯示出有header部分的SOAP格式呢
拜託各位大大幫幫忙了
我在論壇上找到這個相關的文件
但是還是不知道怎麼改....
http://www.javaworld.com.tw/jute/post/view?bid=19&id=15575&sty=3
以下是我自己做範例
(1.Client端)
import java.net.URL;
import org.apache.soap.Constants;
import org.apache.soap.rpc.*;
public class HelloWorldSOAPClient
{
public static void main(String[] args)
{
try
{
String urladdr="http://localhost:8080/soap/servlet/rpcrouter";
String uri = "urn:HelloWorldSOAPServer";
String methodname = "sayHelloWorld";
Call call = new Call();
call.setTargetObjectURI(uri);
call.setMethodName(methodname);
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
URL url = new URL (urladdr);
Response response = call.invoke(url,"");
Parameter r = response.getReturnValue();
System.out.println("Message from Server :" + r.getValue());
}
catch (Exception e)
{e.printStackTrace();}
}
}
(2.server服務)
public class HelloWorldSOAPServer
{
public String sayHelloWorld()
{
return "HelloWorld";
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.135.11.97
※ 編輯: PTTsucker 來自: 140.135.11.97 (01/06 19:19)