2016-10-02 102 views
0

我需要您的帮助。我创建了一个简单的soap web服务,我已经部署在tomcat上。该代码是一个低于SOAP Web服务错误:意外的元素名称:expected = expectedName,actual:{http:// services /} expectedName

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风格融入文档“@SOAPBinding(样式= 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 

你能告诉我为什么它发生了,请问这意味着什么?再次感谢。

回答

0

这里是Wizdler的作者。 wizdler在http://services/名称空间中生成name元素,并且它应该位于默认名称空间(空名称空间)中。这也是错误信息试图说的: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

+0

它的工作原理。谢谢。但有一点:当我有一个具有很多属性的对象时,这个解决方案可能需要很长时间。我应该在java web类中使用什么来自动完成它。我试过(@WebParam(partName =“name”,targetNamespace =“”),但wizdler中的xml不会改变。再次感谢 – user3550446