简体   繁体   English

无法从Java使用Web服务

[英]Can't consume webservice from Java

I created the webservice stubs using axis2-1.5's wsdl2java.bat. 我使用axis2-1.5的wsdl2java.bat创建了Web服务存根。 This created a src folder with the following structure in it: 这创建了一个具有以下结构的src文件夹:

src/net/mycompany/www/services/SessionIntegrationStub.java

The package of the SessionIntegration.java file is: package net.mycompany.www.services; SessionIntegration.java文件的软件包是:package net.mycompany.www.services;

Now, I am trying to use this stub in my java code. 现在,我试图在我的Java代码中使用此存根。 I placed my java file in the same services folder. 我将Java文件放置在相同的服务文件夹中。 I set the same package. 我设置了相同的包裹。 Here is my entire class: 这是我的整个班级:

package net.mycompany.www.services;
import net.mycompany.www.services;

public class DynamicProxy 
{
  public static void main(String[] args) 
  {
    try 
    {
      SessionIntegrationStub stub = new SessionIntegrationStub();
      System.out.println(stub.getSessionIntegration("test"));
    }
    catch (Exception e) 
    {
      System.out.println(e);
    } 
  } 
}

Then I tried to compile this code with the following cmd: 然后,我尝试使用以下cmd编译此代码:

javac DynamicProxy.java

However I keep getting this error message: 但是我不断收到此错误消息:

C:\data\net\mycompany\www\services>javac DynamicProxy.java
DynamicProxy.java:9: cannot find symbol
symbol  : class SessionIntegrationStub
location: package net.mycompany.www.services
import net.mycompany.www.services.SessionIntegrationStub;
                                       ^
DynamicProxy.java:17: cannot find symbol
symbol  : class SessionIntegrationStub
location: class net.mycompany.www.services.DynamicProxy
                        SessionIntegrationStub stub = new SessionIntegrationStub();
                        ^
DynamicProxy.java:17: cannot find symbol
symbol  : class SessionIntegrationStub
location: class net.mycompany.www.services.DynamicProxy
                        SessionIntegrationStub stub = new SessionIntegrationStub();
                                                          ^
3 errors

Any idea what I am missing here? 知道我在这里缺少什么吗?

Update 1: 更新1:

I compiled the stubs (thanks to the answers below) and I got rid of the first error. 我编译了存根(由于下面的答案),我摆脱了第一个错误。 I changed the import to this import net.americanapparel.www.services.*; 我将导入更改为此导入net.americanapparel.www.services。*; however I still get an error for the SessionIntegrationStub: cannot find symbol. 但是我仍然收到SessionIntegrationStub的错误:找不到符号。 I also tried this import: net.americanapparel.www.services.SessionIntegrationStub, but that did not help either. 我也尝试了这种导入:net.americanapparel.www.services.SessionIntegrationStub,但这也没有帮助。 Is there anything else I am missing? 还有什么我想念的吗?

You have to compile your stub first or both together, since wsdl2java only creates a .java file, not the .class file. 由于wsdl2java仅创建一个.java文件,而不是.class文件,因此您必须首先或同时编译存根。 The compiler error clearly says it don't know the SessionIntegrationStub. 编译器错误明确表明它不知道SessionIntegrationStub。

The other answer is right too: you have to 另一个答案也是正确的:您必须

import net.mycompany.www.services.*;

not

import net.mycompany.www.services;

You don't seem to import it. 您似乎没有导入它。

import net.mycompany.www.services.SessionIntegrationStub;

should do the trick. 应该可以。

and then: 接着:

shell$ javac my/package/*.java

which should enable javac to find or compile all the files it needs. 这应该使javac可以查找或编译其所需的所有文件。

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

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