从 Java 调用 .Net WebService [英] Invoking .Net WebService from Java
问题描述
我有一个 .Net webService,它返回一个自定义类,我们称之为MyClass",就像这个例子一样使用:
I had a .Net webService that returns a custom class, lets call it "MyClass", used like this example:
[WebMethod]
public MyClass sampleMethod()
{
return new MyClass();
}
如果从 .Net 应用程序调用时工作正常.
If works ok when invoked from a .Net application.
从使用 AXIS 的 Java 应用程序中,我收到错误MyClass 被引用但未定义".
From a Java application using AXIS I am getting the error "MyClass is referenced but not defined".
我该如何克服这个问题?
How can I overcome this issue?
推荐答案
首先,您必须创建一个 Java 代理:这可以通过将轴指向 Web 服务 WSDL 位置来生成客户端来实现.
First, you have to create a Java proxy: This can be achieved by generating a client by pointing axis to the Web Service WSDL location.
您的 Web 服务可能如下所示:http(s)://server:port/path/service_def.asmx
并在末尾添加 ?wsdl
wsdl 定义(即像这样http(s)://server:port/path/service_def.asmx?wsdl
).
Your Web Service might look like this: http(s)://server:port/path/service_def.asmx
and add ?wsdl
to the end of the wsdl definition (i.e. like this http(s)://server:port/path/service_def.asmx?wsdl
).
从那里,生成客户端并使用代理与您的 .NET Web 服务对话.
From there, generate and client and use the proxy to talk to your .NET Web Service.
PS 可能的原因是您的类未在命名空间中定义.检查您的 WSDL 定义并查看您的类是否有 <xsd:element/>
并尝试向其中添加一个 ns:
并使用 Axis 生成 java 代理.
PS The possible cause for this is that your class is not defined in a namespace. Check your WSDL definition and see if there's an <xsd:element />
for your class and try adding an ns:
to it and generate java proxy with Axis.
这篇关于从 Java 调用 .Net WebService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!