Socket & SOAP

 Reading from and Writing to a Socket
Ref:docs.oracle.com/javase/tutorial/networking/sockets/readingWriting.html

String hostName = args[0];
int portNumber = Integer.parseInt(args[1]);

try (
    Socket echoSocket = new Socket(hostName, portNumber);
    PrintWriter out =
        new PrintWriter(echoSocket.getOutputStream(), true);
        StringBuffer soapBody = new StringBuffer(200);
        //create the soap request
        soapBody.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
          + "<soap:Body>"
          + "<...>");
          + "</soap:Body>"
          + "</soap:Envelope>");
      
        // send an HTTP request to the web service
        out.println("POST /xxx/xxx.asmx HTTP/1.1");
        out.println("Host: servername:portnum);
        out.println("Content-Type: text/xml; charset=utf-8");
        out.println("Content-Length: " + soapBody.length()); 
        out.println("SOAPAction: \"urn:xx_WEBSERVICEname/actionname\"");
        out.println("Connection: Close");
        out.println();
        
        out.println(soapBody);
           
 BufferedReader in =
        new BufferedReader(
            new InputStreamReader(echoSocket.getInputStream()));
    BufferedReader stdIn =
        new BufferedReader(
            new InputStreamReader(System.in))
)

评论

此博客中的热门博文

XML, XSL, HTML

Input in element.eleme.io

Data URI是由RFC 2397 ACE