简体   繁体   English

如何通过JAVA中的SoapClient运行命令

[英]How to run commands through a SoapClient in JAVA

What would be the equivalent of this short php code in java? 这与Java中的这段简短php代码等效吗?

$client = new SoapClient(NULL,
  array(
    "location" => "http://hostname:port/')",
    "uri" => "urn:String",
    "style" => SOAP_RPC,
    'login' => "soapuser",
    'password' => "soappass",
  )
);


$command = "This command will be sent to SOAP";
try {
  $result = $client->executeCommand(new SoapParam($command, "command"));
  return true;
}
catch (Exception $e)  {
  return false;
}

is it possible to achieve the same result with a short java class ? 短的Java类是否有可能达到相同的结果?

update 2 I don't understand your question maybe. 更新2我可能不明白您的问题。 (could you provide the wdsl of your servive?) To create a client like your php code: (您能提供您的servive的wdsl吗?)要创建类似于您的php代码的客户端:

use: 采用:

package com.mkyong.client;

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import com.mkyong.ws.HelloWorld;

public class HelloWorldClient{

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

    URL url = new URL("http://localhost:9999/ws/hello?wsdl");

        //1st argument service URI, refer to wsdl document above
    //2nd argument is service name, refer to wsdl document above
        QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");

        Service service = Service.create(url, qname);

        HelloWorld hello = service.getPort(HelloWorld.class);

        System.out.println(hello.getHelloWorldAsString("mkyong"));

    }

}

copy this file to com/mkyong/client. 将此文件复制到com / mkyong / client。 To compile use javac com/mkyong/client/HelloWorldClient.java and to run use java com/mkyong/client/HelloWorldClient , see also: Compiling four java files within one package using javac and making a java package in the command line 要使用javac com/mkyong/client/HelloWorldClient.java进行编译并运行,请使用java com/mkyong/client/HelloWorldClient进行运行,另请参见: 使用javac在一个程序包中编译四个Java文件在命令行中制作一个Java程序包。

"Mapped" to your php example http://localhost:9999/ws/hello?wsdl will be the equivalent of http://hostname:port/ and executeCommand will be the same as hello.getHelloWorldAsString . “映射”到您的php示例http://localhost:9999/ws/hello?wsdl将等效于http://hostname:port/executeCommand将与hello.getHelloWorldAsString相同。

update try JAX-WS ( http://jax-ws.java.net/ ) 更新尝试JAX-WS( http://jax-ws.java.net/

From http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/ : http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/

package com.mkyong.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{

    @WebMethod String getHelloWorldAsString(String name);

}

Beside the answer here: Working Soap client example you could find many tutorials which tell you how to write a soap client in java: 除了答案: Working Soap客户端示例,您还可以找到许多教程,这些教程告诉您如何在Java中编写Soap客户端:

I guess you are looking for a Java based soap client for PHP soap service. 我猜您正在寻找用于PHP soap服务的基于Java的soap客户端。 I had the similar requirement some time back and could find below nice tutorial for the same: http://development.nedeco.de/blog/2011/08/03/java-client-php-soapserver/ 不久前,我也有类似的要求,并且可以在下面找到相同的漂亮教程: http : //development.nedeco.de/blog/2011/08/03/java-client-php-soapserver/

Also see this free handy book http://www.ksi.edu/thesis/rhuang/rhuang.pdf 另请参阅此免费的便捷书籍http://www.ksi.edu/thesis/rhuang/rhuang.pdf

Groovy is superset of Java, so posting an awesome library you can use in groovy and probably do it in exactly same lines of code as php. Groovy是Java的超集,因此发布了一个很棒的库供您在groovy中使用,并且可能用与php完全相同的代码行来实现。 https://github.com/jwagenleitner/groovy-wslite https://github.com/jwagenleitner/groovy-wslite

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM