在JAVA中创建一个Web服务客户端以从WSDL(w.Eclipse)访问方法 [英] Create a web service client in JAVA to access method from WSDL (w.Eclipse)

查看:208
本文介绍了在JAVA中创建一个Web服务客户端以从WSDL(w.Eclipse)访问方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的网址是:

  http://abc.xyz.com/straw/api/?wsdl 

和方法:

  $ result = $ client-> call($ session,catalog_product.list); 

这是我试过的:


  1. 从Eclipse向导创建一个新的JAVA项目。


  2. r点击项目导航到web service-> web服务客户端。


  3. 提供服务定义 http://abc.xyz.com/straw/api/?wsdl


  4. 在配置中:

    $ b (b)web服务运行时:apache axis


  5. 从滑块选择测试客户端(我也尝试开发客户端有点混乱,因为我必须创建客户端很困惑


  6. 点击完成。




因此,我发现Web服务测试客户端浏览器具有一些方法,输入和结果。
此外,我的资源文件夹中有一些JAVA文件:

  Mage_Api_Model_Server_HandlerBindingStub 
Mage_Api_Model_Server_HandlerPortType
Mage_Api_Model_Server_HandlerPortTypeProxy
MagentoService
MagentoServiceLocator

这些源文件是否由客户端创建? p>

我无法找到方法名称...

  $ result = $ client-> call($ session,catalog_product.list); 

...在任何上述JAVA文件中。



我必须做什么来创建一个Web服务客户端?



从我作为一个可交付项目是什么(这些源文件夹中的这些JAVA文件)



或者我必须编写一个JAVA项目来访问Web服务的方法

  $ result = $ client-> call($ session,catalog_product.list); 

喜欢这个教程:



我的可交付成果为 创建一个Web服务客户端以访问wsdl下面提到的方法



对不起,我的愚蠢,因为我不知道甚至什么输出/可交付的。



任何指导?谢谢!

解决方案

是的,你所做的事实告诉Eclipse,你想要创建所有必要的类以便您能够从Java进行客户端调用Web服务。
现在,我尝试做同样的事情,看看Eclipse生成的东西,但不幸的是(至少对我而言),你所提供的wsdl地址不起作用。然而,我尝试了一个不同的wsdl,并且我得到了一些类似的Eclipse生成的文件。



基本上Eclipse是什么:




  • 当您使用生成的客户端调用Web服务时,它创建表示客户端和服务器之间传递的(XML)数据的模型类。在这种情况下,这些类只是纯Java bean(在这种情况下,它们具有基本名称,没有任何后缀,例如_HanddlerXXX或Service)(我想你没有列出这些,或者你的服务非常简单,它使用JDK类作为模型类,如String,Integer等)。

  • 它还创建一个Java接口,表示Web服务操作端点,在WSDL:这将是MagentoService,它具有与web-serviec操作端点对应的方法(它们返回表示这些端点的对象

  • 最后Mage_Api_Model_Server_HandlerPortType表示Web服务端到端,这个接口必须用你想要的逻辑实现,并使用该实现来实际发送请求到你的web服务



现在在这里有很多的Web服务和SOAP行话,更别提了处理Java中的Web服务(即Axis)的非常相关的框架。我的建议真的是阅读(至少前两章)以下书:



http://www.amazon.fr/Developing-Web-Services-Apache-Axis2/dp/0557254329/ref=sr_1_1?ie=UTF8&qid=1319032081&sr=8 -1



它非常适合用肥皂和休息网络服务的基本概念,它具有从基础到涉及如何实现的很好的例子在Java中使用CXF和Axis2的概念,以及如何使用Eclipse,这只是一本伟大的初学者书籍,您正在这里做什么。


Completely new bee in web services.

I am having the url as:

http://abc.xyz.com/straw/api/?wsdl  

and method:

$result= $client->call($session, "catalog_product.list");   

This is what I have tried:

  1. Created a new JAVA project from Eclipse wizard.

  2. r click on the project navigate to web service-> web service client.

  3. Give the service definition http://abc.xyz.com/straw/api/?wsdl

  4. in configuration:

    • (a) server runtime:tomcat v7.0 server
    • (b) webservice runtime:apache axis
  5. Choose test client from slider (I have also tried develop client a bit confuse,as I have to create client much confused)

  6. Click on finish.

As a result I found web service test client browser with some method, input and result. Also I got some JAVA file in my resources folder:

Mage_Api_Model_Server_HandlerBindingStub  
Mage_Api_Model_Server_HandlerPortType  
Mage_Api_Model_Server_HandlerPortTypeProxy  
MagentoService  
MagentoServiceLocator

Are these source files are created by client?

I am not able to find method name...

$result= $client->call($session, "catalog_product.list");

...in any of the above JAVA files.

What I have to do to create a web service client???

What is expected from me as a deliverable (are these JAVA files in source folder).

Or do I have to write a JAVA project to access the web service's method

$result= $client->call($session, "catalog_product.list");

Like this tutorial:

What is my deliverable for "create a web service client to access method mentioned of below wsdl."

Sorry for my stupidity as I don't know even what to be output/ deliverable.

Any guidance? Thanks!

解决方案

Yes, what you've done in fact is told Eclipse that you'd want to create all the necessary classes such that you'll be able to make client calls to the web-service from Java. Now, I tried doing the same thing you did, to see what Eclipse generates, but unfortunatelly (at least for me) the wsdl address you gave doesn't work. I tried it however with a different wsdl, and I got some similar files generated by Eclipse.

Basically what Eclipse does there is:

  • it creates model classes that represent the (XML) data passed between client and server when you make a call to the web service using the generated client. These classes are, in your case, the ones which are just plain Java beans (in this context they have basic names, without any suffixes such as "_HanddlerXXX" or "Service" (I think you didn't list those here, or your service is very simple and it uses JDK classes as model classes such as String, Integer etc).
  • it also creates a Java interface that represent the web-service operations endpoint that are declared in the WSDL: this would be the "MagentoService", which has methods corresponding to the web-serviec operations endpoint (they return objects representing those endpoints
  • finally "Mage_Api_Model_Server_HandlerPortType" represent an web-service end-point and it offers methods correspondign to that end-point's operations. This interface you must implement with your desired logic and use that implementation to actually send request to your web-service

Now there's a lot of web-service and SOAP jargon here, not to mention a pretty involved framework for dealing with web-services in Java, namely Axis. My recommandations really is to read (at least the first 2 chapters from) the following book:

http://www.amazon.fr/Developing-Web-Services-Apache-Axis2/dp/0557254329/ref=sr_1_1?ie=UTF8&qid=1319032081&sr=8-1

it's excellent for sarting you up with the basic concepts of soap and rest web services, it has great examples from basic to involved of how to implement those notions in java using CXF and Axis2, and how to do this using Eclipse, it's just a great beginner book for what you're doing here.

这篇关于在JAVA中创建一个Web服务客户端以从WSDL(w.Eclipse)访问方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆