在这里,我将列出我为解决这个问题而采取的所有步骤,作为其他人的参考.
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个星期,解决方案是两个步骤,请给这个回答下面一些投票的人.
更新
我的输入对象不是开始解析成XML.
//固定:
你必须告诉程序该属性是这样设置的:
UserCredentials.customerID = User.CustomerID; UserCredentials.customerIDSpecified = true;
fiddler显示:
输入
<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数组
另一个更新
在评论中有人发布了一个link到PHP的错误报告.第二个评论者声称,他通过将所有的消息删除放在其他文件中,并将它们包含在这个主要的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,而一个函数(getAllPersoonData)返回预期的.
WSDL数组defenitions:
<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 defenitions:
<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消息defenitions:
<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功能defenitions:
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返回getAllPersoonData(1)的结果.
对于我来说,这两个功能的防守看起来都一样,我复制粘贴了大部分.我尝试改变命名空间等google.但它没有奏效.有任何想法吗?
如果您需要更多信息,请回复.
编辑2:此外,给这些消息不同的签名将允许您将getPersoonID放在类型定义中,以便您只有一个消息部分.现在,如果你看到Customer.wsdl你有:
<wsdl:message name="getPersoonIDCustomerID">
<wsdl:part name="body" element="ns:UserCredentials"/>
<wsdl:part name="getPersoonID" type="xs:int"/>
</wsdl:message>
您不应该在文档文字消息中有多个部分.
编辑3:如果您不想为每个功能定义一个新元素,那么您将必须切换到RPC文字,该文本将请求包装在wsdl:操作名称中.如果这将修复除.NET以外的所有内容,那么您可以尝试我的SO帖子哄骗.NET阅读RPC文字Web服务.