【问题标题】:Use own WSDL file in JBoss Server (WIldfly 10.0)在 JBoss 服务器中使用自己的 WSDL 文件(WIldfly 10.0)
【发布时间】:2016-09-27 04:19:05
【问题描述】:

如何让 JBoss 使用我提供的 .wsdl 文件?现在,它会自动生成它。例如,如果我有这个接口和类:

计算器网络服务

package test.example.ws;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface CalculatorWebService 
{
    @WebMethod
    public double add(@WebParam(name="number")double ... number);

    @WebMethod
    public double subtract(@WebParam(name="number")double ... number);

    @WebMethod
    public double multiply(@WebParam(name="number")double ... number);

    @WebMethod
    public double divide(@WebParam(name="number")double ... number);
}

计算器WSImpl

package test.example.ws.impl;

import javax.jws.WebService;

import test.example.ws.CalculatorWebService;

@WebService(endpointInterface = "test.example.ws.CalculatorWebService")
public class CalculatorWSImpl implements CalculatorWebService 
{
    public double add(double ... number) {
        if(number.length == 0)
            return 0.0;

        double sum = 0.0;

        for(double num : number)
            sum += num;

        return sum;
    }

    public double subtract(double ... number) {
        if(number.length == 0)
            return 0.0;

        double difference = number[0];

        for(int i = 1; i < number.length; i++)
            difference -= number[i];

        return difference;
    }

    public double multiply(double ... number) {
        if(number.length == 0)
            return 0.0;

        double product = 1.0;

        for(double num : number)
            product *= num;

        return product;
    }

    public double divide(double ... number) {
        if(number.length == 0)
            return 0.0;

        double quotient = number[0];

        for(int i = 1; i < number.length; i++)
            quotient /= number[i];

        return quotient;
    }
}

有了这个web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>WebServices</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>calculatorWebService</servlet-name>
    <servlet-class>test.example.ws.impl.CalculatorWSImpl</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>calculatorWebService</servlet-name>
    <url-pattern>/ws/calculator</url-pattern>
  </servlet-mapping>
</web-app>

Wildfly 10.0 会自动生成这个.wsdl 文件:

<wsdl:definitions name="CalculatorWSImplService" targetNamespace="http://impl.ws.example.test/"><wsdl:import location="http://localhost:8080/WebServices/ws/calculator?wsdl=CalculatorWebService.wsdl" namespace="http://ws.example.test/">
    </wsdl:import><wsdl:binding name="CalculatorWSImplServiceSoapBinding" type="ns1:CalculatorWebService"><soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="add"><soap:operation soapAction="" style="document"/><wsdl:input name="add"><soap:body use="literal"/></wsdl:input><wsdl:output name="addResponse"><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="divide"><soap:operation soapAction="" style="document"/><wsdl:input name="divide"><soap:body use="literal"/></wsdl:input><wsdl:output name="divideResponse"><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="multiply"><soap:operation soapAction="" style="document"/><wsdl:input name="multiply"><soap:body use="literal"/></wsdl:input><wsdl:output name="multiplyResponse"><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="subtract"><soap:operation soapAction="" style="document"/><wsdl:input name="subtract"><soap:body use="literal"/></wsdl:input><wsdl:output name="subtractResponse"><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="CalculatorWSImplService"><wsdl:port binding="tns:CalculatorWSImplServiceSoapBinding" name="CalculatorWSImplPort"><soap:address location="http://localhost:8080/WebServices/ws/calculator"/></wsdl:port></wsdl:service></wsdl:definitions>

我想制作自己的.wsdl 文件并使用它。我需要向web.xml 添加一些内容吗?我该怎么做呢?我想这样做的主要原因是因为我也可以链接我自己的.xsd。如何阻止 JBoss 生成自己的.wsdl

我尝试了谷歌搜索,但我认为我没有搜索正确的关键字,因为我找不到任何东西。

【问题讨论】:

    标签: java web-services jboss wsdl wildfly


    【解决方案1】:

    事实证明这很简单。在您的实现类中,只需将属性 wsdlLocation 添加到 @WebService 注释即可。

    所以在我的例子中,它看起来像:

    @WebService (
        endpointInterface = "test.example.ws.CalculatorWebService",
        wsdlLocation = "path/to/file.wsdl"
    )
    

    如果你这样做,你可能需要在@WebService注解中指定portNameserviceNametargetNamespace属性。所有这些属性都应该在您的 .wsdl 文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-21
      • 2023-01-04
      • 2015-01-16
      • 2020-12-08
      • 2016-03-22
      • 2017-07-17
      • 1970-01-01
      相关资源
      最近更新 更多