运行CXF JAX WS服务的问题

时间:2013-04-08 20:40:29

标签: java jax-ws cxf mule

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

以下是我的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"  >

但这不起作用。 尝试在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                                 *
********************************************************************************

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

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

以下是此服务的wsdl。

我创建了这个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>

2 个答案:

答案 0 :(得分:4)

使用cxf:jaxws-service属性配置port绝对没问题,所以我认为问题出在您的配置中。

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

查看您的WSDL,事情似乎是正确的,因此我的猜测是@WebService上的HelloServiceImpl.class注释包含时髦的值。

应该是:

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

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

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

答案 1 :(得分:0)

example

中未引用<cxf:jaxws-service serviceClass="interface-name and not implementation name>
相关问题