http://apps.hi.baidu.com/share/detail/11053367
上面添加的第4步,在myelipse8.5好像不能成功不知道怎么回事,直接在浏览器输入网址:
http://192.168.13.112:8080/MyWebService/services/
得到如下结果:
---------------------------------------------------------------------------
Available Services:
- MyFristWS [wsdl]
Generated by XFire ( http://xfire.codehaus.org )
---------------------------------------------------------------------------
关于客户端库文件的添加可以在上面新建的时候(4)就选择!
为了能够查看soap报文,在写客户端的时候添加了调试信息【http://xfire.codehaus.org/Logging】:
package com.myclient;
import java.net.URL;
import org.codehaus.xfire.client.Client;
public class GetService {
public static void main(String[] args) throws Exception
{
Client client = new Client(new URL("http://127.0.0.1:8080/MyWebService/services/MyFristWS?wsdl"));
// Tell XFire to cache a DOM document for the various in/out/fault flows
client.addInHandler(new org.codehaus.xfire.util.dom.DOMInHandler());
client.addOutHandler(new org.codehaus.xfire.util.dom.DOMOutHandler());
client.addFaultHandler(new org.codehaus.xfire.util.dom.DOMOutHandler());
// Add a logging handler to each flow
client.addInHandler(new org.codehaus.xfire.util.LoggingHandler());
client.addOutHandler(new org.codehaus.xfire.util.LoggingHandler());
client.addFaultHandler(new org.codehaus.xfire.util.LoggingHandler());
Object[] results = client.invoke("example", new Object[] {"hello"});
System.out.println((String) results[0]);
}
}
运行结果如下:
hello
2010-12-21 11:29:07 org.codehaus.xfire.util.LoggingHandler invoke
信息: <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns1:example xmlns:ns1="http://myserver.com">
<ns1:in0>hello</ns1:in0>
</ns1:example>
</soap:Body>
</soap:Envelope>
2010-12-21 11:29:07 org.codehaus.xfire.util.LoggingHandler invoke
信息: <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns1:exampleResponse xmlns:ns1="http://myserver.com">
<ns1:out>hello</ns1:out>
</ns1:exampleResponse>
</soap:Body>
</soap:Envelope>