SOAP Web服务错误:意外的元素名称:expected = expectedName,actual:{http:// services /} expectedName

时间:2016-10-02 14:34:35

标签: web-services soap wsdl

我需要你的帮助。我已经创建了一个我在tomcat上部署的简单soap web服务。代码是下面的代码

package services;
import java.util.ArrayList;

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@SOAPBinding(style=Style.RPC)
@WebService(wsdlLocation="http://localhost:8080/WS/soap")
public interface servicesInterface {

@WebResult(partName="name")
String createOperation( @WebParam(partName="name",   targetNamespace="/http://services/") String name);
}

及其实施类

package services;

import java.util.ArrayList;
import javax.jws.WebService;
import list.names;

@WebService(endpointInterface="services.servicesInterface")
public class servicesImpl implements servicesInterface{

public String createOperation(String name) {
    System.out.println("CREATE " + name + "\n");
    return name;
}}

然后生成的WSDL是以下

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://services/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://services/" name="servicesImplService">
<types/>
<message name="createOperation">
<part name="name" type="xsd:string"/>
</message>
<message name="createOperationResponse">
<part name="name" type="xsd:string"/>
</message>
<portType name="servicesInterface">
<operation name="createOperation" parameterOrder="name">
<input message="tns:createOperation"/>
<output message="tns:createOperationResponse"/>
</operation>
</portType>
<binding name="servicesImplPortBinding" type="tns:servicesInterface">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="createOperation">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://services/"/>
</input>
<output>
<soap:body use="literal" namespace="http://services/"/>
</output>
</operation>
</binding>
<service name="servicesImplService">
<port name="servicesImplPort" binding="tns:servicesImplPortBinding">
<soap:address location="http://localhost:8080/WS/soap"/>
</port>
</service>
</definitions>

现在,使用我的浏览器中的Wizdler进行测试,我有以下请求

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <createOperation xmlns="http://services/">
            <name>JonDoe</name>
        </createOperation>
    </Body>
</Envelope>

我得到了这个错误:我已经尝试修复了2天。

<?xml version="1.0" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soapenv:Body>
        <soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <faultcode>soapenv:Server</faultcode>
            <faultstring>unexpected element name: expected=name, actual: {http://services/}name</faultstring>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

提前谢谢。

PS:顺便说一句,当我尝试将soapBinding样式更改为Document“@SOAPBinding(style = Style.DOCUMENT)”时,我也遇到了这个错误:

org.apache.catalina.core.StandardContext listenerStart
GRAVE: Exception sending context initialized event to listener instance of    class com.sun.xml.ws.transport.http.servlet.WSServletContextListener
WSSERVLET11: failed to parse runtime descriptor: class:   services.jaxws.CreateOperation could not be found
at  com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:130)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4812)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3828)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:291)
at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5616)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1349)
at java.lang.Thread.run(Unknown Source)
Caused by: class: services.jaxws.CreateOperation could not be found
at com.sun.xml.ws.modeler.RuntimeModeler.getClass(RuntimeModeler.java:269)
at com.sun.xml.ws.modeler.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:558)
at com.sun.xml.ws.modeler.RuntimeModeler.processMethod(RuntimeModeler.java:505)
at com.sun.xml.ws.modeler.RuntimeModeler.processClass(RuntimeModeler.java:353)
at com.sun.xml.ws.modeler.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:249)
at com.sun.xml.ws.server.RuntimeEndpointInfo.createModel(RuntimeEndpointInfo.java:180)
at com.sun.xml.ws.server.RuntimeEndpointInfo.init(RuntimeEndpointInfo.java:326)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.createModelAndMetadata(WSServletContextListener.java:203)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:119)
... 11 more

你能告诉我它为什么会发生,它意味着什么吗?再来一次。

1 个答案:

答案 0 :(得分:0)

Wizdler的作者在这里。 wizdler在name命名空间中生成http://services/元素,它应该在默认命名空间(空命名空间)中。这也是错误消息试图说的内容:unexpected element name: expected=name, actual: {http://services/}name

要解决此问题,请将name元素的命名空间设置为空字符串:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <createOperation xmlns="http://services/">
            <name xmlns="">JonDoe</name>
        </createOperation>
    </Body>
</Envelope>

如果这有帮助,您可以在此处添加新问题:https://github.com/pepri/wizdler/issues