我已经按照使用JAX-WS的示例创建了一个Java Web服务及其客户端程序。
我的服务计划:
import javax.jws.WebService;
import javax.jws.WebMethod;
import java.util.Random;
@WebService
public interface RandService {
@WebMethod
public int next1();
@WebMethod
public int[] nextN(final int n);
}
/
import javax.jws.WebService;
import javax.jws.WebMethod;
import java.util.Random;
@WebService(endpointInterface = "rand2.RandService")
public class RandImpl implements RandService {
private static final int maxRands = 16;
@WebMethod
public int next1() {
return new Random().nextInt();
}
@WebMethod
public int[] nextN(final int n) {
final int k = (n > maxRands) ? maxRands : Math.abs(n);
int[] rands = new int[k];
Random r = new Random();
for (int i = 0; i < k; i++)
rands[i] = r.nextInt();
return rands;
}
}
这是我的客户端程序:
import client.RandServiceService;
import client.RandService;
import java.util.List;
public class RandClient {
public static void main(String[] args) {
// set-up
RandServiceService service = new RandServiceService();
RandService port = service.getRandServicePort();
// sample calls
System.out.println(port.next1());
System.out.println();
List<Integer> nums = port.nextN(4);
for (Integer num : nums)
System.out.println(num);
}
}
程序运行正常,但是如何查看为程序内部生成的SOAP请求和SOAP响应?请帮助我了解如何获取这些细节。
答案 0 :(得分:0)
使用tcpmon,但不再支持
答案 1 :(得分:0)
SoapUI是ws测试的爸爸。 http://www.soapui.org
答案 2 :(得分:0)
SoapUI OpenSource (free)将向您显示客户端和服务器端的SOAP XML。使用此工具,您绝对可以从服务器端看到响应SOAP XML。如果您只是想试试,请下载zip存档版本。 (我通过设置JAVA_HOME并单击SoapUI / bin / soapui.bat启动SoapUI的ZIP版本
以下是快速了解您的网络服务的实施情况。
1. Open SoapUI 2. Create a Project 3. Provide the path to your WSDL file. (If well-formed you will see the operations in your new project a tree control). 4. Open the tree node to an operation and create a SoapUI request template a. Select the operation 1) Right->Click "New Request" b. Name the Request (new node for Request appears in tree) 5. Run a test for your operation. a. Use the property editor below the tree 1) Provide any arguments 2) Provide any authentication b. Right-Click on the Request 1) "Show Request Editor" 5. Ponder your SOAP request envelope XML (on left) 6. Click on the run arrow a. Ponder your SOAP response (on right)