调用网络服务。需要缺失的链接

发布于 2024-10-29 11:07:07 字数 1440 浏览 0 评论 0原文

有人可以填写下面代码中缺少的链接吗?

第一种方式:

Web服务接口文件为HappyService.

JaxWSProxyFactoryBean factory = new JaxWsProxyFactoryBean();

factory.getInterceptors().add(new LoggingInInterceptor());
factory.getInterceptors().add(new LoggingOutInterceptor());

//MISSING LINK. Where does HappyService.class come from? I don't have it
factory.setServiceClass(HappyService.class);

factory.setAddress("http://......../happyService");

//Again how do I get HappyService?
HappyService client = (HappyService) factory.create();

第二种方式:

String UrlString = "Your WSDL URL";   
   String nameSpaceUri = "urn:Foo";
   String serviceName = "MyHelloService";
   String portName = "HelloIFPort";

   URL helloWsdlUrl = new URL(UrlString);

   ServiceFactory serviceFactory = ServiceFactory.newInstance();

   Service helloService =
            serviceFactory.createService(helloWsdlUrl, 
            new QName(nameSpaceUri, serviceName));

   //Where did dynamicproxy.HelloIF come from? This code won't compile as that file does not exist anywhere
   dynamicproxy.HelloIF myProxy = 
            (dynamicproxy.HelloIF) 
            helloService.getPort(
            new QName(nameSpaceUri, portName), 
            dynamicproxy.HelloIF.class); 

        System.out.println(myProxy.sayHello("Buzz"));

任何人如果知道这些接口类从何而来以及它们是如何生成的,请告诉我。看起来我执行 Web 服务调用的唯一方法是手动编写 SOAP 请求,但我真的不想这样做,因为它会变得非常大并且容易出错。

Can someone fill in the missing link in the code below?

First way:

The web service interface file is HappyService.

JaxWSProxyFactoryBean factory = new JaxWsProxyFactoryBean();

factory.getInterceptors().add(new LoggingInInterceptor());
factory.getInterceptors().add(new LoggingOutInterceptor());

//MISSING LINK. Where does HappyService.class come from? I don't have it
factory.setServiceClass(HappyService.class);

factory.setAddress("http://......../happyService");

//Again how do I get HappyService?
HappyService client = (HappyService) factory.create();

Second way:

String UrlString = "Your WSDL URL";   
   String nameSpaceUri = "urn:Foo";
   String serviceName = "MyHelloService";
   String portName = "HelloIFPort";

   URL helloWsdlUrl = new URL(UrlString);

   ServiceFactory serviceFactory = ServiceFactory.newInstance();

   Service helloService =
            serviceFactory.createService(helloWsdlUrl, 
            new QName(nameSpaceUri, serviceName));

   //Where did dynamicproxy.HelloIF come from? This code won't compile as that file does not exist anywhere
   dynamicproxy.HelloIF myProxy = 
            (dynamicproxy.HelloIF) 
            helloService.getPort(
            new QName(nameSpaceUri, portName), 
            dynamicproxy.HelloIF.class); 

        System.out.println(myProxy.sayHello("Buzz"));

Anyone that has a clue as to where these interface classes come from and how they are generated please let me know. It looks like the only way I can do an web service invocation is by writing the SOAP request by hand and I really don't want to do that as it can get very large and error prone.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

因为看清所以看轻 2024-11-05 11:07:07

有许多工具可以从 WSDL 定义文件生成 Web 服务 Java 类。

您可以尝试 JAXB,它是执行此任务的标准 Java 工具。
另一种可能性是 Axis,它的级别更高。

There are many tools that generate webservices Java classes from WSDL definition files.

You could try JAXB, which is the standard Java tool for this task.
An other possibility is Axis, which a level higher.

汐鸠 2024-11-05 11:07:07

您需要一个 SOAP 库,例如 Apache Axis2。该库将包含用于从 WSDL 生成 Java 类的工具。您将使用生成的代码来进行 Web 服务调用。

You need a SOAP library such as Apache Axis2. The library will include tools for generating Java classes from WSDLs. You would use that generated code to make the web service calls.

清浅ˋ旧时光 2024-11-05 11:07:07

根据您的第一个示例,我认为您使用 CXF 框架。

该框架提供了一个名为 wsdl2java 的任务,该任务允许从 WSDL 生成类文件。

生成类后,您可以在代码中使用它们以简单的方式调用 Web 服务,而无需手动构建 SOAP 消息。 CXF 的工作就是做这件事。

Based on your first sample I think you use the CXF framework.

This framework provides a task named wsdl2java that allows to generate classes from a WSDL file.

Once your classes are generated you can use them in your code to call the Web Service in an easy way without having to build the SOAP message by hand. It's CXF's job to do this.

浮光之海 2024-11-05 11:07:07

我认为如果您参考 java 中的一些 Web 服务基础知识

http: //www.oracle.com/technetwork/java/index-jsp-137004.html

http://metro .java.net/

I think it helps if you refer few basics of web-services in java

http://www.oracle.com/technetwork/java/index-jsp-137004.html

http://metro.java.net/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文