转载自: https://blog.csdn.net/qq_34869990/article/details/89678528
1.首先看一下webservice发布是否成功(注意在接下来的步骤中发布webservice的服务器不能关)
2.打开postman软件,地址栏输入webservice url地址,选择post方式
3. Headers中设置Content-Type
4. 在Body中发送数据进行测试,其中xmlns:test="http://service.foxconn.com/" 对应第一步中targetNamespace的值。
下面是本人接口的代码:
ReplyUtil.java:
-
public
class
ReplyUtil {
-
-
public static String getRobotReply(String input) {
-
ArrayList
results =
new ArrayList();
-
//获取数据库连接
-
Connection conn = SqlUtil.getConn(StaticData.url, StaticData.user, StaticData.pwd);
-
PreparedStatement pst =
null;
-
String sql =
"select answer from robotreply where inquiry=?";
-
-
ResultSet rs =
null;
-
String reply =
null;
-
try {
-
pst = conn.prepareStatement(sql);
-
pst.setString(
1, input);
-
rs = pst.executeQuery();
-
//计数结果条数
-
int count =
0;
-
//是否查出标识
-
boolean findFlag =
false;
-
-
while(rs.next()){
-
findFlag =
true;
-
reply = rs.getString(
"answer");
-
results.
add(reply);
-
count++;
-
}
-
//如果找到,则随机选择一条返回
-
if(findFlag){
-
//取随机回复
-
Random random =
new Random();
-
int index = random.nextInt(count);
-
return results.
get(index);
-
}
else{
-
return
"请求不明确,请联系管理员!";
-
}
-
}
catch (SQLException e) {
-
e.printStackTrace();
-
}
finally{
-
SqlUtil.closeResultSet(rs);
-
SqlUtil.closePst(pst);
-
SqlUtil.closeConn(conn);
-
}
-
return reply;
-
}
-
}
RobotReply.java(webservice服务):
-
@SOAPBinding(style = SOAPBinding.Style.RPC)
-
@WebService
-
public
class RobotReply {
-
-
@WebMethod
-
public
@WebResult(name="reply")String getReply(
@WebParam(name="input") String input) {
-
return ReplyUtil.getRobotReply(input);
-
}
-
}
根据发布的webservice发送xml的报文进行测试:注意参数要用 包住。
5. 点击send发送报文数据,查看返回结果: