如何使用Java使用rpc编码的SOAP Web服务

如何使用Java使用rpc编码的SOAP Web服务,java,soap,soap-rpc-encoded,Java,Soap,Soap Rpc Encoded,是否有一种使用java的SOAP web服务的方法,只需使用: 所需的SOAPaction(例如名为“find”的methodname) web服务的URL 标头身份验证(用户名和密码) 最后输出结果 我有一个用php成功使用的示例请求xml文件,但我找不到在java上使用它的正确方法 [更新:web服务的WSDL样式为RPC/编码] [更新#2:您可以找到我是如何解决以下问题的(通过使用IDE生成的java存根)]您可以使用它发送SOAP消息。e、 g: public static voi

是否有一种使用java的SOAP web服务的方法,只需使用:

  • 所需的SOAPaction(例如名为“find”的methodname)
  • web服务的URL
  • 标头身份验证(用户名和密码)
  • 最后输出结果
我有一个用php成功使用的示例请求xml文件,但我找不到在java上使用它的正确方法

[更新:web服务的WSDL样式为RPC/编码]

[更新#2:您可以找到我是如何解决以下问题的(通过使用IDE生成的java存根)]您可以使用它发送SOAP消息。e、 g:

public static void main(String[] args) throws Exception {

    String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
            "<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/\">\r\n" +
            "  <soap:Body>\r\n" +
            "    <ConversionRate xmlns=\"http://www.webserviceX.NET/\">\r\n" +
            "      <FromCurrency>USD</FromCurrency>\r\n" +
            "      <ToCurrency>CNY</ToCurrency>\r\n" +
            "    </ConversionRate>\r\n" +
            "  </soap:Body>\r\n" +
            "</soap:Envelope>";

    Authenticator.setDefault(new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("username", "password".toCharArray());
        }
    });

    URL url = new URL("http://www.webservicex.net/CurrencyConvertor.asmx");
    URLConnection  conn =  url.openConnection();
    conn.setDoOutput(true);
    conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
    conn.setRequestProperty("SOAPAction", "http://www.webserviceX.NET/ConversionRate");

    // Send the request XML
    OutputStream outputStream = conn.getOutputStream();
    outputStream.write(xml.getBytes());
    outputStream.close();

    // Read the response XML
    InputStream inputStream = conn.getInputStream();
    Scanner sc = new Scanner(inputStream, "UTF-8");
    sc.useDelimiter("\\A");
    if (sc.hasNext()) {
        System.out.print(sc.next());
    }
    sc.close();
    inputStream.close();

}
publicstaticvoidmain(字符串[]args)引发异常{
字符串xml=“\r\n”+
“\r\n”+
“\r\n”+
“\r\n”+
“美元\r\n”+
“CNY\r\n”+
“\r\n”+
“\r\n”+
"";
setDefault(新验证器(){
受保护的密码身份验证getPasswordAuthentication(){
返回新的密码身份验证(“用户名”、“密码”.tocharray());
}
});
URL=新URL(“http://www.webservicex.net/CurrencyConvertor.asmx");
URLConnection conn=url.openConnection();
连接设置输出(真);
conn.setRequestProperty(“内容类型”,“text/xml;charset=utf-8”);
conn.setRequestProperty(“SOAPAction”http://www.webserviceX.NET/ConversionRate");
//发送请求XML
OutputStream OutputStream=conn.getOutputStream();
write(xml.getBytes());
outputStream.close();
//读取响应XML
InputStream InputStream=conn.getInputStream();
扫描仪sc=新扫描仪(输入流,“UTF-8”);
sc.useDelimiter(“\\A”);
if(sc.hasNext()){
System.out.print(sc.next());
}
sc.close();
inputStream.close();
}
您可以使用发送SOAP消息。e、 g:

public static void main(String[] args) throws Exception {

    String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
            "<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/\">\r\n" +
            "  <soap:Body>\r\n" +
            "    <ConversionRate xmlns=\"http://www.webserviceX.NET/\">\r\n" +
            "      <FromCurrency>USD</FromCurrency>\r\n" +
            "      <ToCurrency>CNY</ToCurrency>\r\n" +
            "    </ConversionRate>\r\n" +
            "  </soap:Body>\r\n" +
            "</soap:Envelope>";

    Authenticator.setDefault(new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("username", "password".toCharArray());
        }
    });

    URL url = new URL("http://www.webservicex.net/CurrencyConvertor.asmx");
    URLConnection  conn =  url.openConnection();
    conn.setDoOutput(true);
    conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
    conn.setRequestProperty("SOAPAction", "http://www.webserviceX.NET/ConversionRate");

    // Send the request XML
    OutputStream outputStream = conn.getOutputStream();
    outputStream.write(xml.getBytes());
    outputStream.close();

    // Read the response XML
    InputStream inputStream = conn.getInputStream();
    Scanner sc = new Scanner(inputStream, "UTF-8");
    sc.useDelimiter("\\A");
    if (sc.hasNext()) {
        System.out.print(sc.next());
    }
    sc.close();
    inputStream.close();

}
publicstaticvoidmain(字符串[]args)引发异常{
字符串xml=“\r\n”+
“\r\n”+
“\r\n”+
“\r\n”+
“美元\r\n”+
“CNY\r\n”+
“\r\n”+
“\r\n”+
"";
setDefault(新验证器(){
受保护的密码身份验证getPasswordAuthentication(){
返回新的密码身份验证(“用户名”、“密码”.tocharray());
}
});
URL=新URL(“http://www.webservicex.net/CurrencyConvertor.asmx");
URLConnection conn=url.openConnection();
连接设置输出(真);
conn.setRequestProperty(“内容类型”,“text/xml;charset=utf-8”);
conn.setRequestProperty(“SOAPAction”http://www.webserviceX.NET/ConversionRate");
//发送请求XML
OutputStream OutputStream=conn.getOutputStream();
write(xml.getBytes());
outputStream.close();
//读取响应XML
InputStream InputStream=conn.getInputStream();
扫描仪sc=新扫描仪(输入流,“UTF-8”);
sc.useDelimiter(“\\A”);
if(sc.hasNext()){
System.out.print(sc.next());
}
sc.close();
inputStream.close();
}

经过长时间的搜索,我终于找到了使用rpc/encoded
SOAP
web服务的方法。 我决定从wsdl url生成客户机存根

成功的方法是通过此链接(来源:)

在eclipse/netbeans调整生成的代码(java存根)之后,您只需构建您的客户机。 通过使用您生成的类,您可以使用您首选的soap api

e、 g

Auth Auth=new Auth(“用户名”、“密码”);
SearchQuery fsq=新的SearchQuery(“参数1”、“参数2”、“参数3”);
Model_SearchService服务=新Model_SearchServiceLoc();
SearchRequest freq=新的SearchRequest(auth,fsq);
结果r[]=service.getSearchPort()方法(freq);

对于(inti=0;i经过长时间的搜索,我终于找到了一种使用rpc/encoded
SOAP
web服务的方法。 我决定从wsdl url生成客户机存根

成功的方法是通过此链接(来源:)

在eclipse/netbeans调整生成的代码(java存根)之后,您只需构建您的客户机。 通过使用您生成的类,您可以使用您首选的soap api

e、 g

Auth Auth=new Auth(“用户名”、“密码”);
SearchQuery fsq=新的SearchQuery(“参数1”、“参数2”、“参数3”);
Model_SearchService服务=新Model_SearchServiceLoc();
SearchRequest freq=新的SearchRequest(auth,fsq);
结果r[]=service.getSearchPort()方法(freq);

对于(int i=0;iyou搜索了google,没有找到任何使用java的soap Web服务的示例?我也找到了很多文章和ibm帖子,但问题是很多人建议使用JAX-WS和wsimport工具,但wsimport不能“使用”rpc/encoded WSDL。另外,我还发现了另一种使用HttpUrlConnection执行if的方法,但我只得到与访问WSDL url时相同的Web服务器WSDL作为响应。感谢您的帮助,因为“rpc encoded”bit似乎是问题中相当重要的一部分,你应该把它包括在实际问题中,而不仅仅是作为标签。我没有否决“真正的问题”,我否决了一个非特定的问题,这个问题并没有给出很多以前对一个有大量在线文档记录的主题的研究的迹象。你搜索了谷歌,没有找到任何使用java的soap Web服务的例子?我也找到了很多文章和ibm帖子,但问题是很多人建议使用JAX-WS和wsimport工具但是wsimport不能“使用”rpc/编码的WSDL。另外,我还发现了另一种使用HttpUrlConnection的方法,但是我只得到了Web服务器的WSDL作为响应,与我访问WSDL的url时一样。感谢您的帮助,因为“rpc编码”位似乎是问题的一个非常重要的部分,您应该将其包括在