SOAP Server + Andorid klient

0

Witam.

Próbuje stworzyć prosty serwer w języku PHP, z którym za pomocą protokołu SOAP będzie komunikował się klient z systemu Android.

kod serwera:

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("server.wsdl"); // WSDL file for function definitions
$server->addFunction("ChooseColor");    // Same func name as in our WSDL XML, and below
$server->handle();  


function ChooseColor($color)
{
   return $color;
}

kod pliku WSDL:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<definitions name='MyExampleWebServiceAccessPoint' targetNamespace='http://example.org/MultiService'
    xmlns:tns=' http://example.org/MultiService ' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
    xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"  
    xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' xmlns='http://schemas.xmlsoap.org/wsdl/'>
   
<types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.ecerami.com/schema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
            xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        <element name="ChooseColorRequest">
            <complexType><sequence>
                <element minOccurs="1" maxOccurs="1" name="Name" type="string" />
            </sequence></complexType>
        </element>
        <element name="ChooseColorResponse">
            <complexType><sequence>
                <element minOccurs="1" maxOccurs="1" name="Success" type="string" />
            </sequence></complexType>
        </element>
    </schema>
</types>

<message name="ChooseColorRequest">
    <part name="parameters" element="tns:ChooseColorRequest" />
</message>
<message name="ChooseColorResponse">
    <part name="parameters" element="tns:ChooseColorResponse" />
</message>

<message name="ColorHttpPostIn">
    <part name="Color" type="s:string" />
</message>
<message name="ColorHttpPostOut">
    <part name="Body" element="tns:string" />
</message>

<portType name="ChooseColorBinding">
    <operation name="ChooseColor">
        <input message="tns:ChooseColorRequest" />
        <output message="tns:ChooseColorResponse" />
    </operation>
</portType>

<portType name="ColorHttpPost">
    <operation name="ColorHttpPost">
      <input message="tns:ColorHttpPostIn" />
      <output message="tns:ColorHttpPostOut" />
    </operation>
</portType>


<binding name="ChooseColorBinding" type="tns:ChooseColorBinding">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="ChooseColor">
      <soap:operation soapAction="http://100.123.10.205/loyal-localapp/server.php/ChooseColor" style="document" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
</binding>

<binding name="ColorHttpPost" type="tns:ColorHttpPost">
    <http:binding verb = "POST" />
    <operation name="ChooseColor">
        <http:operation location="/ChooseColor"/>
        <input>
        <mime:content type="application/x-www-form-urlencoded" />
      </input>
      <output>
        <mime:mimeXml part="Body" />
      </output>
    </operation>
</binding>


<service name="MyExampleWebServiceAccessPoint">
    <port name="ChooseColorBinding" binding="tns:ChooseColorBinding">
      <soap:address location="http://100.123.10.205/loyal-localapp/server.php"/>
    </port>
    
    <wsdl:port name="TempConvertHttpPost" binding="tns:TempConvertHttpPost">
      <http:address location="http://100.123.10.205/loyal-localapp/server.php" />
    </wsdl:port>

</service>

</definitions>

fragment kodu klienta:

 private static final String SERVICE_URL = "http://100.123.10.205/loyal-localapp/server.php";
     private static final String SERVICE_NAMESPACE = "http://example.org/MultiService";
     private static final String METHOD_CEL_TO_FAHR = "ChooseColor"; 
     private static final String SOAP_ACTION_CEL_TO_FAHR = "http://100.123.10.205/loyal-localapp/server.php/ChooseColor";

Przy wysyłaniu żądania otrzymuje błąd:

'Procedure ChooseColor not present'

Myślę, że problem tkwi w pliku WSDL, lub kodzei serwera. Kod javy bez problemu działa gdy testowałem go dla istniejącego serwisu (np.http://www.w3schools.com/webservices/tempconvert.asmx)

Źle mogłem przypisać wyżej wymienione zmienne.

Może ktoś z Was ma większe doświadczenie z tego typu serwisami i potrafiłbym coś doradzić?

Pozdrawiam :)

0

Zobacz z takim WSDL, u mnie zadziałało:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 
<definitions name="MyExampleWebServiceAccessPoint" 
	targetNamespace="http://example.org/MultiService"
	xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://example.org/MultiService">
 
<types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.ecerami.com/schema">
        <element name="ChooseColorRequest_Element">
            <complexType>
				<sequence>
					<element minOccurs="1" maxOccurs="1" name="Name" type="string" />
				</sequence>
			</complexType>
        </element>
        <element name="ChooseColorResponse_Element">
            <complexType>
				<sequence>
					<element minOccurs="1" maxOccurs="1" name="Success" type="string" />
				</sequence>
			</complexType>
        </element>
    </schema>
</types>
 
<message name="ChooseColorRequest">
    <part name="parameters" element="tns:ChooseColorRequest_Element" />
</message>
<message name="ChooseColorResponse">
    <part name="parameters" element="tns:ChooseColorResponse_Element" />
</message>
 
<portType name="ChooseColor_Type">
    <operation name="ChooseColor">
        <input message="tns:ChooseColorRequest" />
        <output message="tns:ChooseColorResponse" />
    </operation>
</portType>
 
<binding name="ChooseColor_Binding" type="tns:ChooseColor_Type">
	<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="ChooseColor">
      <soap:operation soapAction="ChooseColor" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
</binding>
 
<service name="MyExampleWebServiceAccessPoint">
    <port name="ChooseColor_Port" binding="tns:ChooseColor_Binding">
      <soap:address location="http://100.123.10.205/loyal-localapp/server.php"/>
    </port>
</service>
 
</definitions>

Możesz też użyć takiego bindingu:

<binding name="ChooseColor_Binding" type="tns:ChooseColor_Type">
	<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="ChooseColor">
      <soap:operation soapAction="ChooseColor" style="rpc" />
      <input>
        <soap:body use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
      </output>
    </operation>
</binding>

W każdym razie działa to:
a) przy <soap:binding style="rpc">
b) przy <soap:binding style="document"> i jednoczesnym <soap:operation style="rpc" />

Inaczej nie udało mi się tego odpalić, niemniej WSDL w swojej karierze raczej się nie zajmowałem, więc może ktoś wymyśli to lepiej ;)

1 użytkowników online, w tym zalogowanych: 0, gości: 1