"http://hostnam-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:28:58 25 4
gpt4 key购买 nike

这段简短的 php 代码在 java 中等效于什么?

$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;
}

是否有可能使用一个简短的 java 类实现相同的结果?

最佳答案

更新 2我可能不明白你的问题。 (你能提供你的服务的 wdsl 吗?)创建一个像你的 php 代码一样的客户端:

使用:

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"));

}

}

将此文件复制到 com/mkyong/client。要编译使用 javac com/mkyong/client/HelloWorldClient.java 并使用 java com/mkyong/client/HelloWorldClient 运行,另请参阅:Compiling four java files within one package using javacmaking a java package in the command line

“映射”到您的 php 示例 http://localhost:9999/ws/hello?wsdl 将等同于 http://hostname:port/executeCommand 将与 hello.getHelloWorldAsString 相同。

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

来自 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);

}

除了这里的答案:Working Soap client example你可以找到很多教程,告诉你如何用 java 编写 soap 客户端:

关于java - 如何通过 JAVA 中的 SoapClient 运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18680384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com