java 运行 CXF JAX WS 服务时出现问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15888569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:10:58  来源:igfitidea点击:

Issue running CXF JAX WS Service

javajax-wscxfmule

提问by user1760178

I have exposed a web service using the CXF JAXWS Service via the HTTP outbound.

我已经通过 HTTP 出站使用 CXF JAXWS 服务公开了一个 Web 服务。

Given below is the syntax of my end-point declaration from my Mule config.

下面给出的是我的 Mule 配置中的端点声明的语法。

<http:inbound-endpoint address="http://localhost:8080/HelloService"  exchange-pattern="request-response">
        <cxf:jaxws-service serviceClass="com.example.service.HelloServiceImpl" wsdlLocation="wsdl/helloservice.wsdl"
        namespace="http://example.org/HelloService"          
         port="HelloServicePort"   service="HelloService"  >

But this is no working. It gives the below error when tried to run this on mule server.

但这是行不通的。尝试在 mule 服务器上运行它时会出现以下错误。

2013-04-08 16:34:35,252 ERROR [main] mule.MuleServer (MuleServer.java:474) - 
********************************************************************************
* A Fatal error has occurred while the server was running:                     *
* Could not find definition for port                                           *
* {http://service.example.com/}HelloServiceImplPort.                *
* (org.apache.cxf.service.factory.ServiceConstructionException)                *
*                                                                              *
* The error is fatal, the system will shutdown                                 *
********************************************************************************

It is looking for a different port than what I have mentioned in the service endpoint declaration.

它正在寻找与我在服务端点声明中提到的端口不同的端口。

Please help me understand, what the issue is.

请帮助我理解,这是什么问题。

Given below is the wsdl of this service.

下面给出的是该服务的 wsdl。

I have created this WSDL and then generated code using wsdl2java of cfx. Then Implemented the service interface operations. Then configured the service in a Mule flow.

我已经创建了这个 WSDL,然后使用 cfx 的 wsdl2java 生成了代码。然后实现了服务接口操作。然后在 Mule 流中配置服务。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://example.org/HelloService" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="HelloService" targetNamespace="http://example.org/HelloService"
 xmlns:per="http://example.org/HelloService/person"
 xmlns:comp="http://example.org/HelloService/company"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  >

    <wsdl:types>        
    <xsd:schema targetNamespace="http://example.org/HelloService/company" >    
        <xsd:include schemaLocation="company.xsd"  ></xsd:include>    
    </xsd:schema>
    <xsd:schema targetNamespace="http://example.org/HelloService/person"> 
        <xsd:include schemaLocation="person.xsd"  ></xsd:include>    
    </xsd:schema>
  </wsdl:types>


  <wsdl:message name="addCompanyRequest">
    <wsdl:part element="comp:Company" name="company"/>
  </wsdl:message>

  <wsdl:message name="addPersonRequest">
    <wsdl:part element="per:Person" name="person"/>
  </wsdl:message>

  <wsdl:message name="addCompanyResponse">
    <wsdl:part element="comp:CompResponse" name="response"/>
  </wsdl:message>

  <wsdl:message name="addPersonResponse">
    <wsdl:part element="per:PerResponse" name="response"/>
  </wsdl:message>

  <wsdl:portType name="HelloService">
    <wsdl:operation name="addCompany">
      <wsdl:input message="tns:addCompanyRequest" name="addCompanyRequest" />
      <wsdl:output message="tns:addCompanyResponse" name="addCompanyResponse" />
    </wsdl:operation>

    <wsdl:operation name="addPerson">
      <wsdl:input message="tns:addPersonRequest" name="addPersonRequest" />
      <wsdl:output message="tns:addPersonResponse"  name="addPersonResponse" />
    </wsdl:operation>

  </wsdl:portType>

  <wsdl:binding name="HelloServiceSOAP" type="tns:HelloService">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="addCompany">
      <soap:operation soapAction=""  style="document" />
      <wsdl:input name="addCompanyRequest">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="addCompanyResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>

    <wsdl:operation name="addPerson">
      <soap:operation soapAction=""  style="document" />
      <wsdl:input name="addPersonRequest">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="addPersonResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>

  </wsdl:binding>

  <wsdl:service name="HelloService">
    <wsdl:port binding="tns:HelloServiceSOAP" name="HelloServicePort">
      <soap:address location="http://localhost:8080/HelloService"/>
    </wsdl:port>
  </wsdl:service>  

</wsdl:definitions>

回答by David Dossot

I have absolutely no problem configuring a cxf:jaxws-servicewith a portattribute, so I think the issue is in your configuration.

cxf:jaxws-serviceport属性配置 a 绝对没有问题,所以我认为问题出在你的配置上。

For instance, the error says CXF is looking for {http://service.example.com}HelloServiceImplPortbut surprisingly you're configuring the service namespace as http://example.org/HelloService. Though it doesn't need to be consistent, it usually is.

例如,错误说 CXF 正在寻找,{http://service.example.com}HelloServiceImplPort但令人惊讶的是您将服务命名空间配置为http://example.org/HelloService. 虽然它不需要保持一致,但通常是这样。

Looking at your WSDL, things seem correct so my guess is that the @WebServiceannotation on HelloServiceImpl.classcontains funky values.

看看你的 WSDL,事情似乎是正确的,所以我的猜测是@WebService注释HelloServiceImpl.class包含时髦的值。

It should be:

它应该是:

@WebService(endpointInterface = "...interface class...", targetNamespace = "http://example.org/HelloService", serviceName = "HelloService", portName = "HelloServicePort", wsdlLocation = "wsdl/helloservice.wsdl")

Note that with a properly configured @WebService, you only need this in Mule XML config:

请注意,使用正确配置的@WebService,您只需要在 Mule XML 配置中使用它:

<cxf:jaxws-service serviceClass="com.example.service.HelloServiceImpl" />

回答by Charu Khurana

Isn't <cxf:jaxws-service serviceClass="interface-name and not implementation name>as cited in this example

不是<cxf:jaxws-service serviceClass="interface-name and not implementation name>在这个例子中引用的