简体   繁体   English

如何从java调用ac#webservice

[英]how to call a c# webservice from java

Is there a way to call ac# webservice from java? 有没有办法从java调用ac#webservice? I have a webservice which was written in c# language and I do want use this webservice in java. 我有一个用c#语言编写的web服务,我确实想在java中使用这个webservice。 If there is a way, please let me know. 如果有办法,请告诉我。

Regards Altaico 关心Altaico

A webservice is just a little program that generates some text, which is then sent by HTTP. Web服务只是一个生成一些文本的小程序,然后由HTTP发送。 The text could by Html or Xml (or plain text). 文本可以通过Html或Xml(或纯文本)。 The language that little program is written in is completely irrelevant, since all your Java client will be seeing in text delivered by Http. 编写小程序的语言完全无关紧要,因为所有的Java客户端都会看到Http提供的文本。

Call it exactly as you would call a webservice written in Java or any other language. 完全像调用用Java或任何其他语言编写的Web服务一样调用它。

Web services is a standard protocol. Web服务是一种标准协议。 You can call a C# web service the same way you call a Java web service. 您可以像调用Java Web服务一样调用C#Web服务。 You can generate a client from the WSDL definition file provided by the service. 您可以从服务提供的WSDL定义文件生成客户端。

From a C# (.NET) web service you can get the WSDL definition file in the following URL: 从C#(.NET)Web服务,您可以在以下URL中获取WSDL定义文件:

http://[web_service_virtual_path].asmx?WSDL

I have done this a number of times. 我做了很多次。 Web service support is included in java 1.6 as standard so there are no additional jar files needed. Web服务支持作为标准包含在java 1.6中,因此不需要额外的jar文件。

The starting point is the WSDL url . 起点是WSDL URL This looks like a standard HTTP URL with a ?wsdl on the end. 这看起来像标准HTTP URL,最后带有?wsdl。 As noted by @Germán in his answer it will look something like this: 正如@Germán在他的回答中指出的那样,它看起来像这样:

http://[web_service_virtual_path].asmx?WSDL

The next step is to run wsimport . 下一步是运行wsimport wsimport is part of the Java 1.6 distribution so no additional downloads are necessary. wsimport是Java 1.6发行版的一部分,因此不需要额外的下载。

I have used the following command from the command line to generate the Java client side code based on the wsdl: 我在命令行中使用了以下命令来生成基于wsdl的Java客户端代码:

wsimport -s src -keep -Xnocompile http://[web_service_virtual_path].asmx?WSDL

This will create a java package tree in the src folder and leave the .java files there. 这将在src文件夹中创建一个java包树,并将.java文件保留在那里。

(There may be additional flags that need to be set depending on how the actual web service was created or for example you are hiding behind a proxy server. Run wsimport with no parameters to get a list of these flags or options) (可能还需要设置其他标志,具体取决于实际Web服务的创建方式,或者例如您隐藏在代理服务器后面。运行不带参数的wsimport以获取这些标志或选项的列表)

The web service documentation (even if it is in C# format) will usually be enough for you to continue writing from this point. Web服务文档(即使它是C#格式)通常足以让您继续从这一点开始编写。 This documentation should be available from the writers of the actual web service you are trying to connect to. 您应该从您尝试连接的实际Web服务的编写者处获得此文档。

The language the webservice is written in should be irrelevant -- that's part of the point of using web services. Web服务编写的语言应该是无关紧要的 - 这是使用Web服务的一部分。 In general, yes, you can call webservices from Java. 通常,是的,您可以从Java调用webservices。 One library that can help you with this is Apache Axis . 一个可以帮助您解决此问题的库是Apache Axis

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

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