简体   繁体   English

使用Java调用VB.NET Web服务

[英]Calling a VB.NET web service with Java

What is the best solution (if any) for calling a vb.net web service with Java / JSP? 使用Java / JSP调用vb.net Web服务的最佳解决方案(如果有的话)是什么? If anyone could point me to any examples / references I would very much appreciate it. 如果有人能指出我的任何例子/参考我会非常感激。

Thanks! 谢谢!

For Java to connect to the .NET Web service, it will require that you first generate a WSDL. 要使Java连接到.NET Web服务,首先需要生成WSDL。 This can be done by prepending ?WSDL to the .asmx web service (.NET), eg http://localhost:8080/myApp/myService.asmx?WSDL 这可以通过预先设定来完成?WSDL到的.asmx Web服务(.NET),如http://localhost:8080/myApp/myService.asmx?WSDL

For Java to understand this, you will need a Web Service client: In Java 6, the JAX-WS is the latest specification. 要让Java理解这一点,您将需要一个Web服务客户端:在Java 6中, JAX-WS是最新的规范。

The following client that conforms to the JAX-WS is: 符合JAX-WS的以下客户端是:

These tools allows you to create a java proxy from the WSDL definition. 这些工具允许您从WSDL定义创建Java代理。 In java 6 (in JDK_HOME/bin folder) there are tools (now standard) to convert a WSDL definition to java proxy. 在java 6(在JDK_HOME / bin文件夹中)中,有一些工具(现在是标准的)将WSDL定义转换为Java代理。 The wsimport (windows) allows such operation. wsimport (windows)允许这样的操作。

Once you have a java proxy, you can basically call all the exposed web service methods created to call your web service. 拥有Java代理后,您基本上可以调用所有创建的公开Web服务方法来调用您的Web服务。

This totally depends on what kind of web service you are talking about (RESTful vs. SOAP, etc.). 这完全取决于您所谈论的Web服务类型(RESTful与SOAP等)。 In theory, the whole point of having a web service is to provide this kind of interoperability, so it should definitely be possible. 从理论上讲,拥有Web服务的全部意义在于提供这种互操作性,因此它绝对应该是可行的。 However, without more details its hard to point you in the right direction. 但是,没有更多细节,很难指出你正确的方向。

Really, this question has nothing to do with VB.net, since the client should not need to be exposed to any of the service implementation details. 实际上,这个问题与VB.net无关,因为客户端不需要暴露于任何服务实现细节。

EDIT: Since its a SOAP service, you should be able to create a client based off the service's WSDL. 编辑:由于它是一个SOAP服务,您应该能够基于服务的WSDL创建一个客户端。 There are a variety of tools to help with this. 有很多工具可以帮助解决这个问题。 Here is a tutorial on generating Java code from a WSDL using the WSDL2Java utility. 这是一个使用WSDL2Java实用程序从WSDL生成Java代码的教程。

Java frameworks you should take a look at: 你应该看看Java框架:

If by "VB.NET web service", you mean an ASP.NET Web Service (.asmx file extension), you should be able to consume that with Java with a Soap client. 如果通过“VB.NET Web服务”,您的意思是ASP.NET Web服务(.asmx文件扩展名),您应该能够使用带有Soap客户端的Java来使用它。

Each ASP.NET web service will expose its public contract for that service via a WSDL (Web Service Definition Language) file, which you can access by simply adding ?WSDL after the .asmx of the web service's address. 每个ASP.NET Web服务都将通过WSDL(Web服务定义语言)文件公开其服务的公共合同,您只需在Web服务地址的.asmx之后添加?WSDL即可访问该文件。 The key benefit behind web services based on common protocols such as SOAP is that they allow software to communicate across machine and platform boundaries. 基于SOAP等通用协议的Web服务背后的主要优势在于它们允许软件跨机器和平台边界进行通信。 The WSDL file is the contract that exists between the software applications to make sure they communicate in the same language. WSDL文件是软件应用程序之间存在的合同,以确保它们以相同的语言进行通信。

A good client library will read that WSDL file and will handle the plumbing of communicating with the web service via SOAP-based XML messages. 一个好的客户端库将读取该WSDL文件,并将处理通过基于SOAP的XML消息与Web服务进行通信的管道。 If you really wanted to, you could even hand-craft your SOAP XML messages and communicate via a simple HTTP client. 如果您真的想要,您甚至可以手工制作SOAP XML消息并通过简单的HTTP客户端进行通信。 However, it would be best to use a library that already exists to handle your SOAP plumbing. 但是,最好使用已存在的库来处理SOAP管道。 This lets your application consume the functionality of the web service while making sure you adhere to the web service contract. 这使您的应用程序可以使用Web服务的功能,同时确保您遵守Web服务合同。

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

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