简体   繁体   English

Java soap客户端到wsdl url

[英]Java soap client to wsdl url

i want to call soap function with a few parameters. 我想用一些参数调用soap函数。 I did it python but how can i do it on java ? 我用python做过,但是如何在java上做呢?

my code on python : 我在python上的代码:

        url = 'http://78.188.50.246:8086/iskultur?singleWsdl'
        client = Client(url)

        d = dict(UserId='a', UserPass='b', Barkod=str(value))

        result = client.service.Stok(**d)
        return int(result)

how can i do it on java ? 我如何在Java上做呢?

Thanks for all 谢谢大家

First you need to generate proxy classes. 首先,您需要生成代理类。 You can do that using wsimport (it's a Java SE tool): 您可以使用wsimport (这是Java SE工具)来做到这一点:

wsimport -keep http://78.188.50.246:8086/iskultur?singleWsdl

This will generate classes (in packages) and place the results in the current directory. 这将生成类(在包中)并将结果放置在当前目录中。 I tested your URL and it generated two package hierarchies (one starting in 'org' and the other in 'com'). 我测试了您的URL,它生成了两个包层次结构(一个从“ org”开始,另一个在“ com”中)。 The command above will keep the source code, so you can move those directories to your Java project source path (later you should include this code generation step in your build process). 上面的命令将保留源代码,因此您可以将这些目录移动到Java项目的源路径(以后,应在构建过程中包括此代码生成步骤)。

with the generated classes in your classpath, you now create a Service instance from your WSDL (passing the URL and the namespace qualified name of your service). 在类路径中使用生成的类,现在可以从WSDL创建一个Service实例(传递URL和服务的名称空间限定名称)。 I got that information from the WSDL. 我从WSDL获得了这些信息。

URL wsdlLocation = new URL("http://78.188.50.246:8086/iskultur?singleWsdl");
QName serviceName = new QName("http://tempuri.org/", "EbWCFtoLogo");

Service service = Service.create(wsdlLocation, serviceName);

Then you get a proxy where you can call your SOAP methods with Service.getPort() passing the interface of the port ( IEbWCFtoLogo ). 然后,您将获得一个代理,您可以在其中通过传递端口( IEbWCFtoLogo )的Service.getPort()来调用SOAP方法。 Now you have a reference where you can call your remote SOAP methods. 现在,您有了一个参考,可以在其中调用远程SOAP方法。

IEbWCFtoLogo proxy = service.getPort(IEbWCFtoLogo.class);

The wsimport tool generated a stok() method that receives 3 parameters. wsimport工具生成了一个stok()方法,该方法接收3个参数。 I called with some of the values you used and it returned -1.0 in the code below: 我用您使用的一些值进行了调用,并在下面的代码中返回-1.0

double value = proxy.stok("a", "b", "code");
System.out.println("Result: " + value);

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

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