朋友们,我一直在尝试很多,阅读了很多论坛,但无法理解为什么出现此问题。
我使用契约优先方法创建了一个Jax-WS WebService。创建WSDL和XSD,然后使用wsimport工具生成其余工件,为SEI提供实现。
将WebService应用程序部署到Eclipse Helios中的GlassFish(Glassfish适配器和Eclipse中安装的插件)。通过SoapUI测试了已部署的服务,并且工作正常。
我将此Web服务作为WAR文件部署到Tomcat7.0中。结构为:
WAR -> META-INF -> MANIFEST.MF
-> WEB-INF -> classes -> ...
-> wsdl -> .wsdl and .xsd
-> web.xml
-> sun-jaxws.xml
When I test the webservice through SoapUI, the response I get is an exception as:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>unexpected XML tag. expected: {http://localhost/fundmanagertd}addFund but found: {http://localhost/fundmanagertd}requestAddFund</faultstring>
</S:Fault>
</S:Body>
</S:Envelope>
我认为它在Glassfish中起作用,因为Glassfish正在动态生成所有工件,而不接受已经生成的工件。而Tomcat只采用已部署软件包中的那些。我为什么这么认为,因为仅当未提供sun-jaxws.xml时,Web服务才能在Glassfish中工作,但是当提供时,我无法在“已部署的服务”部分下看到该服务。当Tomcat使用sun-jasws.xml并使用我提供的类并失败时。我不知道为什么会这样。从这里的任何方向将不胜感激。
我正在使用的WSDL:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="http://localhost/fundmanagertd" name="FundManagerTDService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/fundmanagertd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema>
<xsd:import namespace="http://localhost/fundmanagertd" schemaLocation="FundManagerTDService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="addFund">
<part name="parameters" element="tns:requestAddFund"/>
</message>
<message name="addFundResponse">
<part name="parameters" element="tns:responseAddFund"/>
</message>
<portType name="Fund">
<operation name="addFund">
<input message="tns:addFund"/>
<output message="tns:addFundResponse"/>
</operation>
</portType>
<binding name="FundPortBinding" type="tns:Fund">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="addFund">
<soap:operation soapAction="urn:Add"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="FundManagerTDService">
<port name="FundPort" binding="tns:FundPortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>
FundManagerTDService_schema1.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://localhost/fundmanagertd" xmlns:tns="http://localhost/fundmanagertd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="requestAddFund" type="tns:requestAddFund"/>
<xs:element name="responseAddFund" type="tns:responseAddFund"/>
<xs:complexType name="fund">
<xs:sequence>
<xs:element name="annuity" type="tns:annuityType" minOccurs="0"/>
<xs:element name="duration" type="xs:int"/>
<xs:element name="endDate" type="xs:dateTime" minOccurs="0"/>
<xs:element name="id" type="xs:long"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="premium" type="xs:float"/>
<xs:element name="startDate" type="xs:dateTime" minOccurs="0"/>
<xs:element name="type" type="tns:investmentType" minOccurs="0"/>
<xs:element name="value" type="xs:float"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="requestAddFund">
<xs:sequence>
<xs:element name="arg0" type="tns:fund" minOccurs="0"/>
<xs:element name="arg1" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="responseAddFund">
<xs:sequence>
<xs:element name="return" type="xs:long"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="annuityType">
<xs:restriction base="xs:string">
<xs:enumeration value="MONTHLY"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="investmentType">
<xs:restriction base="xs:string">
<xs:enumeration value="MF"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
SoapUI正在自动生成请求,它是:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fun="http://localhost/fundmanagertd">
<soapenv:Header/>
<soapenv:Body>
<fun:requestAddFund>
<!--Optional:-->
<arg0>
<!--Optional:-->
<annuity>?</annuity>
<duration>?</duration>
<!--Optional:-->
<endDate>?</endDate>
<id>?</id>
<!--Optional:-->
<name>?</name>
<premium>?</premium>
<!--Optional:-->
<startDate>?</startDate>
<!--Optional:-->
<type>?</type>
<value>?</value>
</arg0>
<!--Optional:-->
<arg1>?</arg1>
</fun:requestAddFund>
</soapenv:Body>
</soapenv:Envelope>
另外,我尝试创建一个静态客户端来访问我的Web服务,并收到带有“意外XML标签消息...”的SOAPFaultException。
另外,添加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="fundmanagertdservice"
implementation="com.investment.webservice.impl.FundManagerService"
url-pattern="/fundmanagertdsvr"
wsdl="WEB-INF/wsdl/FundManagerTDService.wsdl"/>
</endpoints>
谢谢,
参考方案
我认为SOAP请求主体中的第一个元素必须是您正在调用的操作。
这意味着需要更改自动生成的XML。这正是错误在说什么:
...预期:
... addFund-方法名称-但发现:
... requestAddFund-数据类型名称
页面加载而不是提交时发生struts验证 - java请原谅我;我对Struts有点陌生。我遇到一个问题,即页面加载而不是我实际提交表单时发生了验证。我整天都在论坛上搜寻和搜寻,没有任何运气。我显然做错了一些事情,应该很容易确定,但是我还没有发现问题所在。这是我的struts.xml的片段:<action name="*Test" method="{1}" clas…
DataSourceTransactionManager和JndiObjectFactoryBean和JdbcTemplate的用途是什么? - java以下的用途是什么:org.springframework.jdbc.core.JdbcTemplate org.springframework.jdbc.datasource.DataSourceTransactionManager org.springframework.jndi.JndiObjectFactoryBean <tx:annotatio…
在特定的Swing组件上设置自定义外观 - java是否可以在Swing GUI上仅针对特定组件或组件集设置用于Synth外观的文件,而无需为其他任何组件进行更改? java参考方案 是的,有可能。将类型指定为“区域”,将其更改为“名称”,将值更改为由setName(“ componentName”)给定的特定名称;应用程序中的方法。添加这个<style id="titleBarButtons…
Div单击与单选按钮相同吗? - php有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date…
休眠验证标签不起作用。 BindingResults始终为false - java我的春季项目中的验证无效。我似乎BindingResult没有看到标签。我添加的库女巫列表:使用调试运行应用程序时,我的bindingResult.hasErrors()始终为false。我的学生课程包括以下字段:public class Student { private String firstName; @NotNull(message = "…