【问题标题】:Java generates the WSDL but cant access it using ?wsdlJava 生成 WSDL 但无法使用 ?wsdl 访问它
【发布时间】:2013-01-08 04:14:04
【问题描述】:

我需要我的 Web 服务类返回一个包含以下客户类的数组,该类本身有一个数组。

创建 Web 服务时,将创建 wsdl,但是当我尝试使用其 url 访问它时,它显示以下错误。

添加 ?wsdl 到地址时会显示以下错误

轴错误

无法生成 WSDL!

此位置没有 SOAP 服务

当我不添加 ?wsdl 到地址时会显示以下错误

AXIS error

No service is available at this URL

我的客户类

package myclasses;

public class customer {
private String name;
private int age;
private int[] rankings;

public customer(){
    //Any initializations here.
}

public customer(String n, int a) {
    this.name = n;
    this.age = a;
    rankings = new int[2];
    rankings[0] = 1;
    rankings[1] = 2;

}

public String getName() {
    return name;
}

............Rest of setter and getters goes here .............

}

我的网络服务类

     package services;

import myclasses.customer;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.soap.SOAPBinding; 

@WebService (name="Hellos", 
targetNamespace="http://localhost:8081/Mywebservice2/services/Hellos")  
@SOAPBinding  
(  
      style = SOAPBinding.Style.RPC,  
      use = SOAPBinding.Use.LITERAL,  
      parameterStyle = SOAPBinding.ParameterStyle.WRAPPED  
 )  
public class Hellos {

    @WebMethod
    public @WebResult(name="name",partName="name") String getName(){
        return "Jack";
    }
    
    @WebMethod
    public @WebResult (name="customers",partName="customers") customer[] mycustomers() {
        customer[] cus = new customer[2];
        cus[0] = new customer("Jack", 28);
        cus[1] = new customer("Alex", 29);
        return cus;
        
    }
}

我的 wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://services" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://services" xmlns:intf="http://services" xmlns:tns1="http://myclasses" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://services" xmlns="http://www.w3.org/2001/XMLSchema">
   <import namespace="http://myclasses"/>
   <element name="getName">
    <complexType/>
   </element>
   <element name="getNameResponse">
    <complexType>
     <sequence>
      <element name="getNameReturn" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="mycustomers">
    <complexType/>
   </element>
   <element name="mycustomersResponse">
    <complexType>
     <sequence>
      <element maxOccurs="unbounded" name="mycustomersReturn" type="tns1:customer"/>
     </sequence>
    </complexType>
   </element>
  </schema>
  <schema elementFormDefault="qualified" targetNamespace="http://myclasses" xmlns="http://www.w3.org/2001/XMLSchema">
   <complexType name="customer">
    <sequence>
     <element name="age" type="xsd:int"/>
     <element name="name" nillable="true" type="xsd:string"/>
    </sequence>
   </complexType>
  </schema>
 </wsdl:types>

   <wsdl:message name="getNameResponse">

      <wsdl:part element="impl:getNameResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="mycustomersResponse">

      <wsdl:part element="impl:mycustomersResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="mycustomersRequest">

      <wsdl:part element="impl:mycustomers" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="getNameRequest">

      <wsdl:part element="impl:getName" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:portType name="Hellos">

      <wsdl:operation name="getName">

         <wsdl:input message="impl:getNameRequest" name="getNameRequest">

       </wsdl:input>

         <wsdl:output message="impl:getNameResponse" name="getNameResponse">

       </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="mycustomers">

         <wsdl:input message="impl:mycustomersRequest" name="mycustomersRequest">

       </wsdl:input>

         <wsdl:output message="impl:mycustomersResponse" name="mycustomersResponse">

       </wsdl:output>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="HellosSoapBinding" type="impl:Hellos">

      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="getName">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="getNameRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="getNameResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="mycustomers">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="mycustomersRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="mycustomersResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="HellosService">

      <wsdl:port binding="impl:HellosSoapBinding" name="Hellos">

 

        <wsdlsoap:address location="http://localhost:8081/Mywebservice2/services/Hellos"/>
    
           </wsdl:port>
    
        </wsdl:service>
    
     </wsdl:definitions>

【问题讨论】:

  • @Telthien,感谢您的评论,但我不明白您的问题。
  • 很抱歉。评论放置不当。忽略它:P

标签: java web-services soap wsdl axis


【解决方案1】:

通过服务类“services.Hellos”使用的值类型“myclasses.customer”没有公共默认构造函数

只需在客户类中使用它即可。

public customer()
{
  //Any initializations here.
}

【讨论】:

  • @Srinvas,感谢您的回复,我添加了默认构造函数,但生成的 wsdl 文件显示以下内容:AXIS 错误无法生成 WSDL!此位置没有 SOAP 服务
【解决方案2】:

在你的网络服务定义中试试这个

@SOAPBinding
(
style = SOAPBinding.Style.DOCUMENT,
use = SOAPBinding.Use.LITERAL,
parameterStyle = SOAPBinding.ParameterStyle.WRAPPED
) 

【讨论】:

  • 我在我的方法声明之前和@webmethod之后复制了它,但是eclipse说“这一行有多个标记”。
  • 它需要在服务级别定义,即在@WebService之上
  • 替代方法和更好的解释在这里 - oreilly.com/catalog/javasoap/chapter/ch05.html
  • 您的设计是否可以使用对象列表而不是对象数组?
  • 修改您的代码以返回 ArrayList public ArrayList myCustomers() ,在您的方法主体中将客户添加到 ArrayList 并返回该 ArrayList
【解决方案3】:

我最近遇到了同样的问题。

解决方案:在我的例子中,我使用的是 Axis 1.4,并且正在将应用程序部署在 tomcat 上。但是,由于某种原因,生成的 server-config.wsdd 没有在战争中打包,因此没有部署在 tomcat 上。有一次,我确保发生这种情况,它开始对我正常工作。

【讨论】:

    猜你喜欢
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 2011-10-13
    • 2017-02-05
    相关资源
    最近更新 更多