摘自:http://hi.baidu.com/yangtb/blog/item/0fac2fb31ee56da3d8335aa6.html
前面两种SOAP绑定是指采用SOAP规范来形成HTTPRequest,SOAP:binding是采用SOAP1.1版本。soap12:binding是采用SOAP1.2版本。
<soap:binding
<soap12:binding
<http:binding 是采用HTTP规范来填写消息内容,调用方式如下
交互的 Web 接口:
<html>
<head>
<title>HTTP POST vs. WSDL SOAP Web Services
</title>
</head>
<body>
<br>
<center>
<h2><P>Semantic Web Service invoked
via HTTP/POST by JSP/Java Servlet</h2></P>
<FORM action=
"http://157.182.136.51:8080/HttpApp/servlet/SendHTTPRequest" method="post">
<P><b><font color="blue">Simple Server URL:
</font>
http://157.182.136.76/xshi/httpPost/demo1/VBHandler.aspx </b></P>
<P><b><font color="blue">GIS Server URL:
</font>
http://157.182.136.51/agswsprojs/HttpService/getService.aspx </b></P>
<P><b>(--The GIS Server will create a new buffer feature for any
input point features at your specified distance, e.g. 560 meters.--)</b></P>
<P><b>(--Sample source data can be copied from <font color="red">
http://157.182.136.51/agswsprojs/HttpService/WebForm2.aspx</font>--)</b></P>
<div><b>Server Requested: </b>
<input name="ServerURL" type="text" size="80"/></div>
<br>
<div><TEXTAREA NAME="request" COLS=60 ROWS=25></TEXTAREA>
<TEXTAREA NAME="response" COLS=60 ROWS=25></TEXTAREA></div>
<br>
<b>Request</b>
<INPUT TYPE=SUBMIT VALUE="Submit Request">
<b>Response</b>
</FORM>
<b><P><font color="red">Before click the button,
specify the distance in the BufferDistance tags to c
reate the new buffer feature of the input dataset
</font></P></b>
</center>
</body>
</html>
图 10 显示了 JSP/Java Servlet 客户机用于在服务调用后 与 GIS HTTP 服务器进行交互的 Web 接口:
发送程序:
import java.io.*;
import javax.servlet.*;
import java.util.*;
import java.net.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SendRequestServlet extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String strRequest = request.getParameter("request");
String strURL = request.getParameter("ServerURL");
PrintWriter writer = response.getWriter();
response.setContentType("text/html");
writer.println("<html>");
writer.println("<head>");
writer.println("<title>Your requested service is returned</title>");
writer.println("</head>");
writer.println("<body bgcolor=\"white\">");
String newRequest1, newRequest2, newRequest3;
newRequest1 = strRequest.replaceAll("<","<");
newRequest2 = newRequest1.replaceAll(">",">");
newRequest3 = newRequest2.replaceAll("\"",""");
writer.println("<br><br><center><b>Here is your request (left) and
response
(right) </b></center><br><br>" );
writer.println("<center>");
writer.println("<div><TEXTAREA name=\"request\" COLS=60 ROWS=40>"
+ newRequest3 + "</TEXTAREA>");
String outPut;
outPut="";
try
{
URL url;
URLConnection urlConn;
DataOutputStream printout;
DataInputStream input;
url = new URL (strURL);
urlConn = url.openConnection();
urlConn.setDoInput (true);
urlConn.setDoOutput (true);
urlConn.setUseCaches (false);
urlConn.setRequestProperty
("Content-Type", "application/x-www-form-urlencoded");
printout = new DataOutputStream (urlConn.getOutputStream ());
String content = strRequest;
printout.writeBytes (content);
printout.flush ();
printout.close ();
input = new DataInputStream (urlConn.getInputStream ());
String str;
while (null != ((str = input.readLine())))
{
System.out.println (str);
outPut = outPut + str + "\n";
}
input.close ();
}
catch (MalformedURLException me)
{
System.err.println("MalformedURLException: " + me);
}
catch (IOException ioe)
{
System.err.println("IOException: " + ioe.getMessage());
}
String newResponse1, newResponse2, newResponse3;
newResponse1 = outPut.replaceAll("<","<");
newResponse2 = newResponse1.replaceAll(">",">");
newResponse3 = newResponse2.replaceAll("\"",""");
writer.println("<TEXTAREA name=\"request\" COLS=60 ROWS=40>" +
newResponse3
+ "</TEXTAREA> </div>");
writer.println("</center>");
writer.println("</body>");
writer.println("</html>");
}
}