0

我创建了一个简单的 HelloWorldWS 项目,可以在带有 Metro 2.2 的 Tomcat 7 上运行。我已经在本地 tomcat 服务器上使用 ant 脚本安装了 Metro 库。我还将这些库添加到了我在 JDK 内的 JDK + JRE 中创建的认可文件夹中。JDK(1.7.0 64位)

这是 Web 服务类的片段:

package za.co.atheba.ws;

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

@WebService
@SOAPBinding(style = Style.RPC)
public class Customer {
    @WebMethod
    public String hello(final String name){
        return "Hello " +name;
    }

}

我在 web.xml 中添加了 ws servlet:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <listener>
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>

    <servlet>
        <description>JAX-WS endpoint</description>
        <display-name>WSServlet</display-name>
        <servlet-name>WSServlet</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>WSServlet</servlet-name>
        <!--
            The url-pattern gets appended to the application's root context which is the name of the .war.
            If the war is packaged in HugeWebServices.war and the url-pattern is set to <url-pattern>/webservices/*</url-pattern>,
            then the servlet context/url will be host:port/HugeWebServices/webservices.
        -->
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>

</web-app>

并将其连接到 sun-jaxws.xml:

<?xml version="1.0" encoding="UTF-8"?>

<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">

    <endpoint
        name="CustomerService"
        implementation="za.co.atheba.ws.Customer"
        wsdl="WEB-INF/wsdl/CustomerService.wsdl"
        url-pattern="/CustomerService"/>


</endpoints>

我打包为 .war 并成功部署到 Tomcat。我可以正确查看wsdl...

我尝试使用 Eclipse Web 服务资源管理器对 Web 服务进行测试,但操作返回“IWAB0135E 发生意外错误。java.net.SocketException 软件导致连接中止:recv 失败”

然后,我尝试在 wsdl 上调用 wsimport 以生成客户端工件,但收到此错误:

[ERROR] failed.noservice=Could not find wsdl:service in the provided WSDL(s):

 At least one WSDL with at least one service definition needs to be provided.


Exception in thread "main" javax.xml.stream.FactoryConfigurationError: Provider
com.ctc.wstx.stax.WstxInputFactory not found
        at javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
        at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:163)
        at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
        at javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136
)
        at com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.getXMLIn
putFactory(XMLStreamReaderFactory.java:98)
        at com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.<clinit>
(XMLStreamReaderFactory.java:67)
        at com.sun.xml.internal.ws.api.addressing.WSEndpointReference.<init>(WSE
ndpointReference.java:157)
        at com.sun.xml.internal.ws.api.addressing.AddressingVersion.<init>(Addre
ssingVersion.java:426)
        at com.sun.xml.internal.ws.api.addressing.AddressingVersion.<init>(Addre
ssingVersion.java:57)
        at com.sun.xml.internal.ws.api.addressing.AddressingVersion$1.<init>(Add
ressingVersion.java:59)
        at com.sun.xml.internal.ws.api.addressing.AddressingVersion.<clinit>(Add
ressingVersion.java:59)
        at com.sun.tools.internal.ws.wsdl.parser.MemberSubmissionAddressingExten
sionHandler.getNamespaceURI(MemberSubmissionAddressingExtensionHandler.java:51)
        at com.sun.tools.internal.ws.wsdl.parser.WSDLParser.register(WSDLParser.
java:130)
        at com.sun.tools.internal.ws.wsdl.parser.WSDLParser.<init>(WSDLParser.ja
va:114)
        at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildMod
el(WSDLModeler.java:99)
        at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.jav
a:178)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:120)
        at com.sun.tools.internal.ws.WsImport.main(WsImport.java:42)

我尝试了两种方法 1) 允许 jax-ws 生成 wsdl & 2) 使用 wsgen 从我编写的代码创建 wsdl。

这是wsdl:

<!--
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.2.1-1 (tags/2.2.1-1-7267; 2012-08-30T14:04:51+0000) JAXWS-RI/2.2.7 JAXWS/2.2 svn-revision#unknown. 
-->
<!--  WSgen created wsdl  -->
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:tns="http://ws.atheba.co.za/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" targetNamespace="http://ws.atheba.co.za/" name="CustomerService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.atheba.co.za/" schemaLocation="http://localhost:8080/HelloWorldWS/CustomerService?xsd=1"/>
</xsd:schema>
</types>
<message name="hello">
<part name="parameters" element="tns:hello"/>
</message>
<message name="helloResponse">
<part name="parameters" element="tns:helloResponse"/>
</message>
<portType name="Customer">
<operation name="hello">
<input wsam:Action="http://ws.atheba.co.za/Customer/helloRequest" message="tns:hello"/>
<output wsam:Action="http://ws.atheba.co.za/Customer/helloResponse" message="tns:helloResponse"/>
</operation>
</portType>
<binding name="CustomerPortBinding" type="tns:Customer">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="hello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="CustomerService">
<port name="CustomerPort" binding="tns:CustomerPortBinding">
<soap:address location="http://localhost:8080/HelloWorldWS/CustomerService"/>
</port>
</service>
</definitions>

在这两种情况下,服务都正确部署,但尝试针对 wsdl 创建客户端失败。Jax-ws 应该很简单?任何在正确方向上的帮助将不胜感激......

4

1 回答 1

0

已解决:使用 Wireshark 捕获 HTTP 数据包并意识到我没有收到任何数据。localhost 正在通过我们的网络代理。修复了代理设置,一切都按预期工作!!!

于 2013-05-28T11:31:57.547 回答