开发者社区> 问答> 正文

从给定的WSDL生成SOAP Web服务

我有一个WSDL文件(不是由我管理),必须使用该文件来生成类以调用Java EE应用程序中的Web服务。我RSA用来自动生成Java类。我获得了一个RendimentiWs包含Web服务方法签名的接口。然后,我在另一个类中实现此接口RendimentiWsService。当我调用该方法时,出现以下错误:

javax.xml.ws.soap.SOAPFaultException: javax.xml.bind.JAXBException: class Calc nor any of its super class is known to this context

我认为下面的代码可能有助于理解问题。 WSDL文件

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://soap.mylocation/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://soap.mylocation" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Rendimenti" targetNamespace="http://soap.mylocation">
   <import namespace="http://soap.mylocation" location="RendimentiWs.wsdl" />
   <binding name="RendimentiPortBinding" type="ns1:RendimentiWs">
      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
      <operation name="Calc">
         <soap:operation soapAction="" />
         <input>
            <soap:body parts="parameters" use="literal" />
            <soap:header message="ns1:Calc" part="srToken" use="literal" />
         </input>
         <output>
            <soap:body use="literal" />
         </output>
         <fault name="WsException">
            <soap:fault name="WsException" use="literal" />
         </fault>
      </operation>
   </binding>
   <service name="Rendimenti">
      <port name="RendimentiPort" binding="tns:RendimentiPortBinding">
         <soap:address location="http://mylocation" />
      </port>
   </service>
</definitions>

Calc班

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Calc", propOrder = {
    "prm"
})
public class Calc implements Serializable{

    protected RendPrm prm;

    /**
     * @return
     *     possible object is
     *     {@link RendPrm }
     *     
     */
    public RendPrm getPrm() {
        return prm;
    }

    /**
     * @param value
     *     allowed object is
     *     {@link RendPrm }  
     */
    public void setPrm(RendPrm value) {
        this.prm = value;
    }
}

calc()方法的Java接口RendimentiWs

@WebService(name = "RendimentiWs", targetNamespace = "http://soap.mylocation/")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({
    j.b.p.i.p.j.ObjectFactory.class,
    i.c.s.srtoken.ObjectFactory.class
})
public interface RendimentiWs {
    /**
     * 
     * @param srToken
     * @param parameters
     * @return
     *     returns j.s.CalcResponse
     * @throws WsException_Exception
     */
    @WebMethod(operationName = "Calc")
    @WebResult(name = "CalcResponse", targetNamespace = "http://soap.mylocation/", partName = "result")
    @Action(input = "http://soap.mylocation/RendimentiWs/CalcRequest", output = "http://soap.mylocation/RendimentiWs/CalcResponse", fault = {
        @FaultAction(className = WsException_Exception.class, value = "http://soap.mylocation/RendimentiWs/Calc/Fault/WsException")
    })
    public CalcResponse calc(
        @WebParam(name = "parameters", targetNamespace = "http://soap.mylocation/", partName = "parameters")
        Calc parameters,
        @WebParam(name = "srToken", targetNamespace = "http://s.c.i/srtoken", header = true, partName = "srToken")
        String srToken)
        throws WsException_Exception;
}

Java实现RendimentiWsService

public class RendimentiWsService implements RendimentiWs {

    private static String ENDPOINT = "http://myendpoint/Rendimenti?wsdl";

    @Override
    public CalcResponse calc(Calc parameters, String srToken) throws WsException_Exception {

        CalcResponse response = new CalcResponse();
        URL endpoint;

        try {
            endpoint = new URL(ENDPOINT);
            Rendimenti rend = new Rendimenti(endpoint);
            response = rend.getRendimentiPort().calc(parameters, srToken);
        } catch(MalformedURLException e) {
        } catch(Exception e) {
        }
        return response;
    }
}

到目前为止,我已经从WSDL发布了自动生成的代码。我还尝试了以下解决方案:

@XmlRootElement在Calc类上添加了注释-不变 在服务调用之前将以下内容添加到我的实现类中:

JAXBContext context = JAXBContext.newInstance(Calc.class);

没有任何变化,在这种情况下,我还会遇到以下错误:

com.ibm.jtc.jax.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
La proprietà rendOutFilter è presente ma non specificata in @XmlType.propOrder

我很难找到解决方案,因为该错误似乎非常普遍。另外,我也不明白问题是否可能出在WSDL上不正确/不完整,或者我是否缺少实施的一部分。任何提示都非常感谢,谢谢。

展开
收起
垚tutu 2019-12-04 17:08:49 638 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Web应用系统性能优化 立即下载
高性能Web架构之缓存体系 立即下载
PWA:移动Web的现在与未来 立即下载