🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.java
Article #425

Problemas con acceso dinámico a un Web Service

#425
From: Leto Atreides
Date: Thu, 06 Sep 2007 12:37
118 lines
5365 bytes
Hola a todos:

Tengo el siguiente Web Service de prueba:

@WebService()
public class TestWebService {
  @WebMethod
  public String sayHello(@WebParam(name = "name") String name) {
    return "Hello " + name + "!";
  }
}

Y tengo un cliente generado con el NetBeans que accede correctamente a
�l. Ahora bien, el problema es que si cambio el Web Service de servidor
tengo que volver a compilar mi aplicaci�n asoci�ndolo al nuevo servidor.
Para evitar esto, he visto por internet el siguiente c�digo:

String wsdlURL =
"http://localhost:8084/TestWebApplication/TestWebService?wsdl";
String serviceName = "TestWebServiceService";
String portName = "TestWebServicePort";
String operationName = "sayHello";
try {
  // create the Service client object using the wsdl and his service name
  QName serviceQName = new QName(wsdlURL, serviceName);
  ServiceFactory factory = ServiceFactory.newInstance();
  Service service = factory.createService(serviceQName);
  // Call object
  QName portQName = new QName(wsdlURL, portName);
  QName operationQName = new QName(wsdlURL, operationName);
  Call call = service.createCall(portQName,operationQName);
  // input parameter
  call.addParameter("name", serviceQName,ParameterMode.IN);
  // setting return type
  call.setReturnType(XMLType.XSD_STRING);
  // specify the RPC-style operation.
  call.setProperty(Call.OPERATION_STYLE_PROPERTY, "rpc");
  // and the encoding style
  call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "");
  // the target endpoint
  call.setTargetEndpointAddress(wsdlURL);
  // Invoke the method readLSpercent
  Object[] myArgs = {"Leto Atreides"};
  Object lsVal =  call.invoke(myArgs);

  System.out.println("Result:  " +  lsVal.toString());
}
catch(Throwable th) {
  th.printStackTrace();
}

Pero cuando ejecuto el cliente, en el servidor me aparece el siguiente
error:

Caused by: javax.xml.ws.soap.SOAPFaultException: Cannot find the
dispatch method at
com.sun.xml.ws.encoding.soap.SOAPDecoder.raiseFault(SOAPDecoder.java:674)
        at
com.sun.xml.ws.encoding.soap.server.SOAPXMLDecoder.decodeDispatchMethod(SOAPXMLDecoder.java:152)
        at
com.sun.xml.ws.encoding.soap.SOAPDecoder.decodeBodyContent(SOAPDecoder.java:337)
        at
com.sun.xml.ws.encoding.soap.SOAPDecoder.decodeBody(SOAPDecoder.java:327)
        at
com.sun.xml.ws.encoding.soap.SOAPDecoder.decodeEnvelope(SOAPDecoder.java:250)
        at
com.sun.xml.ws.encoding.soap.server.SOAPXMLDecoder.toInternalMessage(SOAPXMLDecoder.java:81)


Googleando por ah� he le�do que el problema est� en los namespaces pero
ni s� como solucionarlo, ni estoy seguro que sea eso.

Pego aqu� el wsdl a ver si alguna alma caritativa me puede ayudar:

<?xml version="1.0" encoding="UTF-8"?><definitions
xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://test/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="http://test/" name="TestWebServiceService">
  <types>
    <xsd:schema>
      <xsd:import
schemaLocation="http://localhost:8084/TestWebApplication/TestWebService?xsd=1"
namespace="http://test/"></xsd:import>
    </xsd:schema>
  </types>
  <message name="sayHello">
    <part element="tns:sayHello" name="parameters"></part>
  </message>
  <message name="sayHelloResponse">
    <part element="tns:sayHelloResponse" name="parameters"></part>
  </message>
  <portType name="TestWebService">
    <operation name="sayHello">
      <input message="tns:sayHello"></input>
      <output message="tns:sayHelloResponse"></output>
    </operation>
  </portType>
  <binding name="TestWebServicePortBinding" type="tns:TestWebService">
    <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"></soap:binding>
    <operation name="sayHello">
      <soap:operation soapAction=""></soap:operation>
      <input>
        <soap:body use="literal"></soap:body>
      </input>
      <output>
        <soap:body use="literal"></soap:body>
      </output>
    </operation>
  </binding>
  <service name="TestWebServiceService">
    <port name="TestWebServicePort" binding="tns:TestWebServicePortBinding">
      <soap:address
location="http://localhost:8084/TestWebApplication/TestWebService"></soap:address>
    </port>
  </service>
</definitions>
Technical Details
Message-ID: <fbosn5$uah$1@serrella.cpd.ua.es>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!ecngs!feeder.ecngs.de!130.59.10.21.MISMATCH!kanaga.switch.ch!switch.ch!news.rediris.es!news.uv.es!news.ua.es!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1116f3,32da743cb4816089,start
X-Google-Attributes: gid1116f3,public,usenet
X-Google-Language: ENGLISH,ASCII
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!ecngs!feeder.ecngs.de!130.59.10.21.MISMATCH!kanaga.switch.ch!switch.ch!news.rediris.es!news.uv.es!news.ua.es!not-for-mail
From: Leto Atreides <leto_ii@eresmas.com>
Newsgroups: es.comp.lenguajes.java
Subject: Problemas con acceso dinámico a un Web Service
Date: Thu, 06 Sep 2007 14:37:17 +0200
Organization: Universidad de Alicante
Lines: 118
Message-ID: <fbosn5$uah$1@serrella.cpd.ua.es>
NNTP-Posting-Host: 172.16.242.116
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: serrella.cpd.ua.es 1189082661 31057 172.16.242.116 (6 Sep 2007 12:44:21 GMT)
X-Complaints-To: news@localhost
NNTP-Posting-Date: Thu, 6 Sep 2007 12:44:21 +0000 (UTC)
User-Agent: Thunderbird 1.5.0.10 (X11/20060911)