Я пытаюсь использовать мыльный сервис JAX-WS, веб-сервис, которым я занимаюсь, это калькулятор, и с другого компьютера в сети я пытаюсь использовать приложение, но оно не работает, так как Я получаю следующую ошибку:
Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Unable to find distribution method for {http: // principal /} add Please see the server log to find more detail about exact cause of the failure.
Файл WSDL выглядит следующим образом, и клиент (по мне) настроен правильно, согласно найденной информации:
<!--
Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
-->
<!--
Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
-->
<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://web.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://web.com/" name="CalculadoraImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://web.com/" schemaLocation="http://192.168.0.19:8089/Calculadora?xsd=1"/>
</xsd:schema>
</types>
<message name="sumar">
<part name="parameters" element="tns:sumar"/>
</message>
<message name="sumarResponse">
<part name="parameters" element="tns:sumarResponse"/>
</message>
<message name="restar">
<part name="parameters" element="tns:restar"/>
</message>
<message name="restarResponse">
<part name="parameters" element="tns:restarResponse"/>
</message>
<message name="multiplicar">
<part name="parameters" element="tns:multiplicar"/>
</message>
<message name="multiplicarResponse">
<part name="parameters" element="tns:multiplicarResponse"/>
</message>
<message name="dividir">
<part name="parameters" element="tns:dividir"/>
</message>
<message name="dividirResponse">
<part name="parameters" element="tns:dividirResponse"/>
</message>
<message name="modulo">
<part name="parameters" element="tns:modulo"/>
</message>
<message name="moduloResponse">
<part name="parameters" element="tns:moduloResponse"/>
</message>
<portType name="Calculadora">
<operation name="sumar">
<input wsam:Action="http://web.com/Calculadora/sumarRequest" message="tns:sumar"/>
<output wsam:Action="http://web.com/Calculadora/sumarResponse" message="tns:sumarResponse"/>
</operation>
<operation name="restar">
<input wsam:Action="http://web.com/Calculadora/restarRequest" message="tns:restar"/>
<output wsam:Action="http://web.com/Calculadora/restarResponse" message="tns:restarResponse"/>
</operation>
<operation name="multiplicar">
<input wsam:Action="http://web.com/Calculadora/multiplicarRequest" message="tns:multiplicar"/>
<output wsam:Action="http://web.com/Calculadora/multiplicarResponse" message="tns:multiplicarResponse"/>
</operation>
<operation name="dividir">
<input wsam:Action="http://web.com/Calculadora/dividirRequest" message="tns:dividir"/>
<output wsam:Action="http://web.com/Calculadora/dividirResponse" message="tns:dividirResponse"/>
</operation>
<operation name="modulo">
<input wsam:Action="http://web.com/Calculadora/moduloRequest" message="tns:modulo"/>
<output wsam:Action="http://web.com/Calculadora/moduloResponse" message="tns:moduloResponse"/>
</operation>
</portType>
<binding name="CalculadoraImplPortBinding" type="tns:Calculadora">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="sumar">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="restar">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="multiplicar">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="dividir">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="modulo">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="CalculadoraImplService">
<port name="CalculadoraImplPort" binding="tns:CalculadoraImplPortBinding">
<soap:address location="http://192.168.0.19:8089/Calculadora"/>
</port>
</service>
</definitions>
Кроме того, это код клиента, который очень прост:
package principal;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class Principal {
private static final String NAMESPACE = "http://web.com/";
private static String URL = "http://192.168.0.19:8089/Calculadora?wsdl"; //Cambiar por mi dirección IP
private static final String METHOD_NAME_SUMAR = "sumar";
private static final String METHOD_NAME_RESTAR = "restar";
private static final String METHOD_NAME_MULTIPLICAR = "multiplicar";
private static final String METHOD_NAME_DIVIDIR = "dividir";
private static final String METHOD_NAME_MODULO = "modulo";
private static final String SOAP_ACTION = "http://web.com/sumar";
public Principal() {
}
public static void main(String[] args) throws Exception {
URL url = new URL(URL);
QName qname = new QName(NAMESPACE, "CalculadoraImplService");
Service service = Service.create(url, qname);
qname = new QName(NAMESPACE, "CalculadoraImplPort");
Calculadora calculadora = service.getPort(qname, Calculadora.class);
System.out.println(calculadora.sumar(1d, 1d));
}
}
Кроме того, интерфейс Calculadora
, который находится на сервере и клиенте:
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface Calculadora {
@WebMethod
public String sumar(@WebParam(name = "numero1")Double numero1, @WebParam(name = "numero2")Double numero2);
@WebMethod
public String restar(@WebParam(name = "numero1")Double numero1, @WebParam(name = "numero2")Double numero2);
@WebMethod
public String multiplicar(@WebParam(name = "numero1")Double numero1, @WebParam(name = "numero2")Double numero2);
@WebMethod
public String dividir(@WebParam(name = "numero1")Double numero1, @WebParam(name = "numero2")Double numero2);
@WebMethod
public String modulo(@WebParam(name = "numero1")Double numero1, @WebParam(name = "numero2")Double numero2);
}
Класс CalculadoraImpl
- это реализация функций, определенных в предыдущем интерфейсе, это класс сервера.
package com.web;
import javax.jws.WebService;
@WebService(endpointInterface = "com.web.Calculadora")
public class CalculadoraImpl {
public String sumar(Double numero1, Double numero2) {
Double resultado = numero1 + numero2;
System.out.println("El resultado de la suma " + numero1 + "+" + numero2 + " es: " + resultado);
return "El resultado de la suma " + numero1 + "+" + numero2 + " es: " + resultado;
}
public String restar(Double numero1, Double numero2) {
Double resultado = numero1 - numero2;
System.out.println("El resultado de la resta " + numero1 + "-" + numero2 + " es: " + resultado);
return "El resultado de la resta " + numero1 + "-" + numero2 + " es: " + resultado;
}
public String multiplicar(Double numero1, Double numero2) {
Double resultado = numero1 * numero2;
System.out.println("El resultado de la multiplicacion " + numero1 + "*" + numero2 + " es: " + resultado);
return "El resultado de la multiplicacion " + numero1 + "*" + numero2 + " es: " + resultado;
}
public String dividir(Double numero1, Double numero2) {
Double resultado = numero1 / numero2;
System.out.println("El resultado de la division " + numero1 + "/" + numero2 + " es: " + resultado);
return "El resultado de la division " + numero1 + "/" + numero2 + " es: " + resultado;
}
public String modulo(Double numero1, Double numero2) {
Double res = numero1 % numero2;
System.out.println("El resultado del modulo entre " + numero1 + "%" + numero2 + "es: " + res);
return "El resultado del modulo entre " + numero1 + "%" + numero2 + "es: " + res;
}
}
Наконец, главное приложение сервера.
package com.web;
import javax.xml.ws.Endpoint;
public class CalculadoraWSPublisher {
public static void main(String[] args) {
Endpoint.publish("http://192.168.0.19:8089/Calculadora", new CalculadoraImpl());
}
}
Мой вопрос: как я могу исправить эту ошибку? Прежде чем уйти один за другим, мне удалось их исправить, но с описанной ранее ошибкой это заняло несколько часов. У меня все настроено, как говорят некоторые сайты.