`

Ruby webSevice 客户端

阅读更多

 我的这个服务端是用Ruby做的,以下是我的客户端

public String getSoapInputStream(String username,String password) {

      try {

        //该字符串是通过《soapUI 4.5.2工具》解析的

        String soapRequestData = "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "

            + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""

            +"  xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" "

            +"  xmlns:urn=\"urn:ActionWebService\">"

            +"<soapenv:Header/>"

            +"<soapenv:Body>"

            +"<urn:CreateWebservice soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"

            +"<username xsi:type=\"xsd:string\">"+username+"</username>"

            +"<password xsi:type=\"xsd:string\">"+password+"</password>"

            +"</urn:CreateWebservice>"

            +"</soapenv:Body>"

            +"</soapenv:Envelope>";

////以下地址是通过《soapUI 4.5.2工具》解析的后的地址

           URL url = new URL("地址");

           URLConnection conn = url.openConnection();

           conn.setUseCaches(false);

           conn.setDoInput(true);

           conn.setDoOutput(true);

          

           conn.setRequestProperty("Content-Length", Integer.toString(soapRequestData

                 .length()));

           conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");

           conn.setRequestProperty("SOAPAction",

                 "http://WebXml.com.cn/getSupportCity");

          

           OutputStream os = conn.getOutputStream();

           OutputStreamWriter osw = new OutputStreamWriter(os, "utf-8");

           osw.write(soapRequestData);

           osw.flush();

           osw.close();

           StringBuilder sTotalString = new StringBuilder();

           String sCurrentLine = "";

           InputStream is = conn.getInputStream();

           BufferedReader l_reader = new BufferedReader(new InputStreamReader(

                 is));

           while ((sCurrentLine = l_reader.readLine()) != null) {

              sTotalString.append(sCurrentLine);

           }

           System.out.println(sTotalString.toString());

           return sTotalString.toString();

      }catch (Exception e) {

        e.printStackTrace();

        returnnull;

      }

   }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics