PHP-функция WSDL возвращает ноль, в то время как другая функция возвращает ожидаемый результат

Summary

Здесь я перечислю все шаги, которые я предпринял, чтобы решить эту проблему, в качестве ссылки для других.

1. PHP, stupidly enough, 'listens' to the input message of a function to define what function it should use. So give every one of your functions a different input message, even though it uses the same type or element. You may think this is quite some work for you to solve but it can be done like this:

<xsi:complexType name="UserCredentials">
<xsi:attribute name="customerID" type="xsi:int"/>
</xsi:complexType>

<xsi:element name="UserCredentials" type="types:UserCredentials"/>
<xsi:element name="UserCredentials1" type="types:UserCredentials"/>

<wsdl:message name="getCustomerCredentials">
 <wsdl:part name="body" element="types:UserCredentials"/>
</wsdl:message>
<wsdl:message name="getCustomerCredentials1">
<wsdl:part name="body" element="types:UserCredentials1"/>
</wsdl:message>

Затем Visual Studio скулил, я потратил пару дней, чтобы разобраться с этой глупой идиотской простой вещью, просто скажите программе, что вы только что установили свойство objects:

 UserCredentials.customerID = User.CustomerID;
 UserCredentials.customerIDSpecified = true;

И это все. Я сам не могу в это поверить. Я провожу 1,5 недели, решение состоит из двух шагов, пожалуйста, дайте этому парню, который ответил ниже, несколько голосов.

Update

Мой входной объект НЕ начинается анализировать в XML.

// Fix:

Вы должны сообщить программе, что свойство установлено так:

UserCredentials.customerID = User.CustomerID;
UserCredentials.customerIDSpecified = true;

Скрипач показывает это:

вход

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UserCredentials2 xmlns="http://5.157.80.21/servicehandler/wsdl_service.wsdl"/>   
</s:Body>
</s:Envelope>

Выход

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="types">
<SOAP-ENV:Body>
<ns1:PersoonArray/>
</SOAP-ENV:Body>
</SOAP-ENV:E‌​nvelope>

Что-то не так с этим кодом?

    public static List<Klant> GetAllPersonen()
    {
        List<Klant> list = new List<Klant>();

        WeGotchaService.Persoon[] servicePersonen = dpc.getAllPersoonData(UserCredentials);

        foreach (WeGotchaService.Persoon p in servicePersonen)
        {
            Klant k = new Klant(p);
            list.Add(k);
        }

        return list;
    }

Update to comment below

<xsi:complexType name="UserCredentials">
        <xsi:attribute name="customerID" type="xsi:int"/>       
    </xsi:complexType>
        <xsi:element name="UserCredentials" type="tns:UserCredentials" />
        <xsi:element name="UserCredentials2" type="tns:UserCredentials"/>

 <wsdl:message name="getCustomerCredentials">
    <wsdl:part name="body" element="ns:UserCredentials"/>
</wsdl:message>
<wsdl:message name="getCustomerCredentials2">
    <wsdl:part name="body" element="ns:UserCredentials2"/>
</wsdl:message>

    <wsdl:operation name="getAllLessenData">
        <wsdl:input message="ns:getCustomerCredentials"/>
        <wsdl:output message="ns2:LessenList"/>
    </wsdl:operation>
    <wsdl:operation name="getAllPersoonData">
        <wsdl:input message="ns:getCustomerCredentials2"/>
        <wsdl:output message="ns3:PersoonList"/>
    </wsdl:operation>

Кажется, это работает, за исключением того, что теперь он возвращает массив count = 0 в VS10

Another Update

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

UPDATE:

Поэтому я изменил порядок функций, определенных в методе привязки, и выяснил следующее: работает только первая функция, определенная в области привязки, поэтому в этом случае работает только мой getAllLessenData, потому что я поставил его выше всех остальных. Кто-нибудь видит ошибку?

 <wsdl:binding name="DataBinding" type="tns:DataPort">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getAllLessenData">
        <soap:operation soapAction="" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getAllPersoonData">
        <soap:operation soapAction="" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getAllBetalingData">
        <soap:operation soapAction="" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getPersoonLessenData">
        <soap:operation soapAction="" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getPersoonBetalingenData">
        <soap:operation soapAction="" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>

end of update

У меня небольшая проблема с WSLD (снова)

все мои getAllLessenData (и другие функции) возвращают NULL, а одна функция (getAllPersoonData) возвращает ожидаемое.

Определения массива WSDL:

<xsi:element name="PersoonArray">
            <xsi:complexType>
                <xsi:sequence>
                    <xsi:element name="Persoon" type="tns:Persoon" maxOccurs="unbounded"/>
                </xsi:sequence>
            </xsi:complexType>
        </xsi:element>
        <xsi:element name="LessenArray">
            <xsi:complexType>
                <xsi:sequence>
                    <xsi:element name="Les" type="tns:Les" maxOccurs="unbounded"/>
                </xsi:sequence>
            </xsi:complexType>
        </xsi:element>

WSDL complexType определения:

        <xsi:complexType name="Les">
            <xsi:attribute name="ID" type="xsi:int"/>
            // lots of stuff //
            <xsi:attribute name="Definitief" type="xsi:boolean"/>
        </xsi:complexType>
        <xsi:complexType name="Persoon">
            <xsi:attribute name="ID" type="xsi:int"/>
            <// lots of stuff //
            <xsi:attribute name="Laatste_keer_bewerkt" type="xsi:dateTime"/>
        </xsi:complexType>

Определения сообщений WSDL:

<wsdl:message name="getCustomerID">
    <wsdl:part name="CustomerID" type="xs:int"/>
</wsdl:message>
<wsdl:message name="PersoonList">
    <wsdl:part name="PersoonList" element="tns:PersoonArray"/>
</wsdl:message>
    <wsdl:message name="LessenList">
    <wsdl:part name="LessenList" element="tns:LessenArray"/>
</wsdl:message>

WSDL portType defenition

 <wsdl:operation name="getAllPersoonData">
        <wsdl:input message="tns:getCustomerID"/>
        <wsdl:output message="tns:PersoonList"/>
    </wsdl:operation>
    <wsdl:operation name="getAllLessenData">
        <wsdl:input message="tns:getCustomerID"/>
        <wsdl:output message="tns:LessenList"/>
    </wsdl:operation>

WSDL Обязательная защита

        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getAllPersoonData">
        <soap:operation soapAction="http://localhost/weGotcha/servicehandler/servicehandler.php" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getAllLessenData">
        <soap:operation soapAction="http://localhost/weGotcha/servicehandler/servicehandler.php" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>

Определения функций PHP:

function getAllPersoonData($customer_ID)
{
   connectToDB();
//////////// yes I use mysqli now /////////////
   $sql = "SELECT * FROM personen WHERE Customer_ID='". $customer_ID ."'";

   $sql = mysql_query($sql) or die(mysql_error());
   $result = array();
   while($row = mysql_fetch_array($sql))
   {
  $row["Kosten_totaal"] = mysql_fetch_array(mysql_query("SELECT SUM(Kosten) FROM lessen WHERE Persoon_ID='". $row["ID"] ."'"))[0];
    $row["Totaal_betaald"] = mysql_fetch_array(mysql_query("SELECT SUM(Bedrag) FROM betalingen WHERE Persoon_ID='". $row["ID"] ."'"))[0];
    $lkbDatum = strtotime($row["Laatste_keer_bewerkt"]);
  $row["Laatste_keer_bewerkt"] = date("Y-m-d", $lkbDatum) . "T". date("H:i:s", $lkbDatum);
  $result[] = $row;             
}
mysql_close();

   return $result;
 }


 function getAllLessenData($customer_ID)
 {
$sql = "SELECT * FROM lessen WHERE Customer_ID='". $customer_ID ."'";
//////////// yes I use mysqli now /////////////
connectToDB();

    $sql = mysql_query($sql) or die(mysql_error());
$result = array();
while($row = mysql_fetch_array($sql))
{
  $result[] = $row;
}
mysql_close();

    return $result;
 }

 $server = new SoapServer("wsdl_service.wsdl");
 $server->AddFunction("getAllPersoonData");
 $server->AddFunction("getAllBetalingData");
 $server->AddFunction("getPersoonBetalingData");
 $server->AddFunction("getAllLessenData");
 $server->AddFunction("getPersoonLessenData");
 $server->handle();

test.php

$client = new SoapClient("http://localhost/weGotcha/servicehandler/wsdl_service.wsdl", array("trace" => 1));

var_dump($client->__getFunctions());

var_dump($client->getAllLessenData(1));

var_dump($client->__getLastRequest());
var_dump($client->__getLastResponse());

который возвращает:

array (size=5)
  0 => string 'PersoonArray getAllPersoonData(int $CustomerID)' (length=47)
  1 => string 'LessenArray getAllLessenData(int $CustomerID)' (length=45)
  2 => string 'BetalingenArray getAllBetalingData(int $CustomerID)' (length=51)
  3 => string 'LessenArray getPersoonLessenData(int $getCustomerID, int $getPersoonID)' (length=71)
  4 => string 'BetalingenArray getPersoonBetalingenData(int $getCustomerID, int $getPersoonID)' (length=79)
null
string '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><CustomerID>1</CustomerID></SOAP-ENV:Body></SOAP-ENV:Envelope>
' (length=195)
string '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:ns1="http://localhost/weGotcha/servicehandler/wsdl_service.wsdl"><SOAP-ENV:Body> <ns1:PersoonArray><ns1:Persoon ID="1" Voornaam="xxxx" Achternaam="xxxx"  Adres="xxxx" Postcode="xxxx" Woonplaats="xxxx"  Email_adres="xxxx" Telefoonnummer="xxxx" Geboortedatum="0001-01-01" CBR_kandidaatnummer="12381233" Rijbewijs="2" Theorie_behaald="false" Theorie_po'... (length=3096)

В моей базе данных есть строки, и вызов getAllLessenData (1) непосредственно из моего servicehandler.php возвращает ожидаемые результаты. однако в моем test.php он просто возвращает NULL, а getLastResponse возвращает результаты из getAllPersoonData (1).

Обе функции функции выглядят одинаково для меня, черт возьми, я скопировал большинство из них. Я пытался изменить пространства имен и т. Д. Google. но это не сработало. Есть идеи?

Если вам нужно больше информации, пожалуйста, ответьте.

Ответы на вопрос(1)

Ваш ответ на вопрос