概要
ここでは、この問題を解決するために私が行ったすべての手順を、他の人の参考としてリストします。
1. 愚かなことに、PHP は関数の入力メッセージを「リッスン」して、使用する関数を定義します。したがって、同じ型または要素を使用していても、関数ごとに異なる入力メッセージを指定してください。これを解決するにはかなりの作業が必要だと思うかもしれませんが、次のように実行できます。
<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 が泣き言を言っていました。私はこのばかばかしい単純なことを理解するのに数日を費やしました。オブジェクト プロパティを設定したことをプログラムに伝えるだけです。
UserCredentials.customerID = User.CustomerID;
UserCredentials.customerIDSpecified = true;
以上です。私自身信じられません。私は 1.5 週間を費やしています。解決策は 2 つのステップです。以下に回答したこの人に投票してください。
アップデート
入力オブジェクトが XML に解析されていません。
//修理:
プロパティが次のように設定されていることをプログラムに伝える必要があります。
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:Envelope>
このコードに何か問題がありますか?
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;
}
以下のコメントを更新
<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>
VS10 で count=0 配列を返すようになったことを除いて、これは機能しているようです。
別のアップデート
コメントで、誰かが PHP のバグ レポートへのリンクを投稿しました。最後から 2 番目のコメンターは、すべてのメッセージ定義を他のファイルに配置し、このメインの WSDL ドキュメントに含めることで、私と同じ問題を回避したと主張しました。私はこれを試しましたが、うまくいきませんでした。何も変わりませんでした。
アップデート:
そこで、バインディング メソッドで定義された関数の順序を変更し、次のことを見つけました。バインディング領域で定義された最初の関数のみが機能するため、この場合は 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>
更新の終わり
WSLD に少し問題があります (再び)
私の getAllLessenData (およびその他の関数) はすべて NULL を返しますが、1 つの関数 (getAllPersonData) は期待どおりの値を返します。
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 定義
<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)
データベースに行があり、servicehandler.php から直接 getAllLessenData(1) を呼び出すと、期待される結果が返されます。ただし、私の test.php では単に NULL を返し、getLastResponse は getAllPersonData(1) からの結果を返します。
どちらの関数定義も同じように見えますが、ほとんどをコピーして貼り付けました。名前空間などを変更してみました。しかし、うまくいきませんでした。何か案は?
さらに情報が必要な場合は、返信してください。