Java Jax-WS клиент и PHP сервер - PullRequest
0 голосов
/ 11 мая 2011

Я пытаюсь получить доступ к простому классу сервера PHP через клиент Java через SOAP с файлом WSDL. Но я всегда получаю ошибку. Я много искал в поисковых системах и изменил кое-где. К сожалению, безуспешно.

Я использую Eclipse для Java и XAMPP для локального сервера. Я изменил хорошо работающий файл WSDL с на этот (клиент Java и сервер Java) веб-службы.

Сообщение об ошибке следующее:

Exception in thread "main" com.sun.xml.internal.ws.protocol.soap.MessageCreationException: Couldn't create SOAP message due to exception: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
    at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(Unknown Source)
    at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)
    at com.sun.xml.internal.ws.client.Stub.process(Unknown Source)
    at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(Unknown Source)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
    at $Proxy22.addValues(Unknown Source)
    at localhost._80.calculator.client.CalculatorClientPHP.main(CalculatorClientPHP.java:10)
Caused by: com.sun.xml.internal.ws.streaming.XMLStreamReaderException: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
    at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.wrapException(Unknown Source)
    at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.next(Unknown Source)
    at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextContent(Unknown Source)
    at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextElementContent(Unknown Source)
    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(Unknown Source)
    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(Unknown Source)
    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(Unknown Source)
    ... 15 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source)
    at com.sun.xml.internal.ws.util.xml.XMLStreamReaderFilter.next(Unknown Source)
    ... 21 more

Мой простой скрипт на PHP-сервере (который работает с PHP-клиентом в режиме WSDL):

<?php 

// Do not cache wsdl file
ini_set("soap.wsdl_cache_enabled", "0");

function addValues($a, $b) {
  return $a + $b;
}

$server = new SoapServer("http://localhost/calculator/calculator.wsdl");
$server->addFunction("addValues");
$server->handle();

?>

Полагаю, в WSDL есть что-то (отсутствует), что беспокоит не PHP-клиента, а Java-клиента. Файл WSDL находится в UTF-8 без спецификации.

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost:80/calculator/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://localhost:80/calculator/" name="CalculatorService">
<types/>
<message name="addValues">
<part name="arg0" type="xsd:int"/>
<part name="arg1" type="xsd:int"/>
</message>
<message name="addValuesResponse">
<part name="return" type="xsd:long"/>
</message>
<portType name="Calculator">
<operation name="addValues" parameterOrder="arg0 arg1">
<input message="tns:addValues"/>
<output message="tns:addValuesResponse"/>
</operation>
</portType>
<binding name="CalculatorPortBinding" type="tns:Calculator">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="addValues">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://localhost:80/calculator/"/>
</input>
<output>
<soap:body use="literal" namespace="http://localhost:80/calculator/"/>
</output>
</operation>
</binding>
<service name="CalculatorService">
<port name="CalculatorPort" binding="tns:CalculatorPortBinding">
<soap:address location="http://localhost:80/calculator/server.php"/>
</port>
</service>
</definitions>

Каждый совет приветствуется. Заранее спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...