如何与Java中基于JAX-WS的SOAP Web服务进行通信?

时间:2014-09-27 15:16:09

标签: java web-services soap wsdl

我搜索谷歌,但我找不到办法做到这一点。我有一个使用JAX-WS构建在netbeans中的SOAP Web服务。我的java客户端代码无法访问gerated wsdl。我试图访问的方式是错误的吗?有人帮忙......

我的网络服务代码

@WebService(serviceName = "HolaMundo") 
public class HolaMundo { 

@WebMethod(operationName = "hello") 
public String hello(@WebParam(name = "name") String txt) { 
return "Hello " + txt + " !"; 
} 
}

生成wsdl

<!-- 
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-. 
--> 
<!-- 
 Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-. 
--> 
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://publicar.ws.org.mx/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://publicar.ws.org.mx/" name="HolaMundo"> 
<types> 
<xsd:schema> 
<xsd:import namespace="http://publicar.ws.org.mx/" schemaLocation="http://localhost:8084/HolaMundo/HolaMundo?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="HolaMundo"> 
<operation name="hello"> 
<input wsam:Action="http://publicar.ws.org.mx/HolaMundo/helloRequest" message="tns:hello"/> 
<output wsam:Action="http://publicar.ws.org.mx/HolaMundo/helloResponse" message="tns:helloResponse"/> 
</operation> 
</portType> 
<binding name="HolaMundoPortBinding" type="tns:HolaMundo"> 
<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="HolaMundo"> 
<port name="HolaMundoPort" binding="tns:HolaMundoPortBinding"> 
<soap:address location="http://localhost:8084/HolaMundo/HolaMundo"/> 
</port> 
</service> 
</definitions>

Java客户端代码

public class cliente { 
    public cliente() { 
    } 

    public static String consumir(Object[] parametros){ 
        String regresar = null; 
        Service service = null;    
        Call call       = null; 
        String endpoint = null; 
        try { 
          endpoint = "http://localhost:8084/HolaMundo/HolaMundo";          
          service = new Service(); 
          call = (Call) service.createCall(); 
          call.setTargetEndpointAddress(new java.net.URL(endpoint)); 
          call.setOperationName("hello");          
          regresar=String.valueOf(call.invoke(parametros));          
        }// try 
        catch (Exception e) { 
          e.printStackTrace(); 
        }// catch 
        finally { 
          return regresar; 
        }// finally 
      } 

    public static void main(String[] args) { 
        try {            
            String parametro = "José"; 
            String respuesta = consumir(new Object[]{parametro}); 
            System.out.println("respuesta: --->" + respuesta); 
        } catch (Exception e) { 
            System.err.println(e.toString()); 
        } 
    } 
} 

但我收到了错误

AxisFault 
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client 
 faultSubcode: 
 faultString: Cannot find dispatch method for {}hello 
 faultActor: 
 faultNode: 
 faultDetail: 
   {http://xml.apache.org/axis/}stackTrace:Cannot find dispatch method for {}hello 
帮助我。感谢

0 个答案:

没有答案