2012-05-11 67 views
6

Estoy intentando acceder a un servicio web (dos archivos más abajo). El cliente está utilizando ASP.NET/C# para su arquitectura web. Puedo agregar la referencia web, pero de alguna manera no puedo generar una clase proxy para el archivo wsdl. El objetivo es usar la función en el archivo server.php para que pueda usar xmlstring para mostrar los datos en el sitio web ASP.NET. Cualquier ayuda será muy apreciada. Muchas graciasCliente ASP.NET/C# para consumir un servicio web PHP/MYSQL (WSDL)


archivo server.php. Este archivo tiene una función php que extrae datos de un archivo mysql db y la función devuelve los datos como una cadena XML.

<?php 
//WEB SERVICE FUNCTION TO EXTRACT DATA FROM CLIENT B INTO XML FORMAT 
function getXML() 
{ 
//CONNECT TO THE DATABASE SERVER 
$dbserverIP = "xxxxxxx"; 
$dbusername = "xxxxxxx"; 
$dbpassword = "xxxxxxx"; 
$dbconnection = mysql_connect($dbserverIP,$dbusername,$dbpassword) 
or die ("The connection to the database server failed."); 

//CONNECT TO THE DATABASE 
$dbname = "xxxxxxxx"; 
$dbselectok = mysql_select_db($dbname,$dbconnection) 
or die ("The connection to the database failed."); 

//QUERY THE DATABASE 
$sqlquery = "SELECT * FROM videogames"; 
$sqlresult = mysql_query($sqlquery,$dbconnection) 
or die ("Error in executing the SQL statement"); 

//CREATE XML STRING 
$xmlstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; 
$xmlstring.= "<videogames>"; 

while ($row = mysql_fetch_array($sqlresult)) 
{ 
    $xmlstring .= "\t<game>\r\n"; 
     $xmlstring .= "\t\t<gametitle>" .$row["gametitle"]. "</gametitle>\r\n"; 
     $xmlstring .= "\t\t<genre>" .$row["genre"]. "</genre>\r\n"; 
     $xmlstring .= "\t\t<year>" .$row["year"]. "</year>\r\n"; 
     $xmlstring .= "\t\t<platform>" .$row["platform"]. "</platform>\r\n"; 
     $xmlstring .= "\t\t<agerating>" .$row["agerating"]. "</agerating>\r\n"; 
     $xmlstring .= "\t\t<price>" .$row["price"]. "</price>\r\n"; 
    $xmlstring .= "\t</game>\r\n"; 
} 

$xmlstring.= "</videogames>"; 

//WRITE XML STRING TO EXTERNAL FILE 
$filename = "videogames.xml"; 
$fileaccessmode = "w"; 
$fptr = fopen($filename,$fileaccessmode); 
fwrite($fptr,$xmlstring); 
fclose($fptr); 

//FREE UP MEMORY 
mysql_free_result($sqlresult); 
mysql_close($dbconnection); 

return $xmlstring; 

} 

//CODE TO DISABLE THE WSDLE CACHE 
ini_set("soap.wsdl_cache_enabled","0"); 

//DEFINE SOAP SERVER INSTANCE AND RELATED WSDL FILE 
//THE service.wsdl FILE IS IN THE SAME FOLDER AS THIS server.php FILE 
$server = new SoapServer("service.wsdl"); 

//ADD FUNCTION TO THE SERVER INSTANCE 
$server->addFunction("getXML"); 

//ACTIVATE THE SOAP HANDLER 
$server->handle(); 

?> 

Este es el archivo WSDL vinculado al archivo server.php.

<?xml version ='1.0' encoding ='UTF-8' ?> 

<!-- ====================== DEFINITIONS ====================== --> 

<definitions name="MyWebService" 
    targetNamespace="http://cet-apache-04.cet.bolton.ac.uk/student/mib1bee/CST3017/assignment/scenario1/service.wsdl" 
    xmlns="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:tns="http://cet-apache-04.cet.bolton.ac.uk/student/mib1bee/CST3017/assignment/scenario1/service.wsdl" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

<!-- ====================== TYPES ============================ --> 
<!-- No need for type definitions as only xsd built-in ======= --> 
<!-- data types are used          --> 
<!-- ========================================================= --> 

<!-- ====================== MESSAGE ========================== --> 

<message name="getXML_Request"> 
<part name="input" /> 
</message> 

<message name="getXML_Response"> 
<part name="xmlString" type="xsd:string"/> 
</message> 

<!-- ====================== PORT TYPE ============================ --> 

<portType name="myWebService_PortType"> 

<operation name="getXML"> 
    <input message="tns:getXML_Request"/> 
    <output message="tns:getXML_Response"/> 
</operation> 

</portType> 

<!-- ======================= BINDING ============================= --> 

<binding name="myWebService_Binding" type="tns:myWebService_PortType"> 
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 

<operation name="getXML"> 
    <input> 
    <soap:body use="literal"/> 
    </input> 
    <output> 
    <soap:body use="literal"/> 
    </output> 
</operation> 

</binding> 

<!-- ======================= SERVICE ============================= --> 

<service name="myWebService_Service"> 
<port name="myWebService_Port" binding="tns:myWebService_Binding"> 
    <soap:address location="http://cet-apache-04.cet.bolton.ac.uk/student/mib1bee/CST3017/assignment/scenario1/server.php"/> 
</port> 
</service> 

</definitions> 
+0

Tal vez porque no es un especialista en servidores PHP-jabón, pero me preguntaba donde el código XML se convierte en un mensaje de jabón, con sus etiquetas de jabón muy específicas. Su WSDL está declarando un servicio soap, pero su respuesta parece ser un XML simple. –

+0

Entonces, para entender este derecho, ¿el cliente es C# y el servidor es PHP? ¿O es al revés? Si intenta generar una clase proxy para un cliente C#, ¿cuál es el error al hacerlo? – valheru

+1

¿Has resuelto tu problema? –

Respuesta

0

que debe arreglar su WSDL:

<operation name="getXML"> 
    <soap:operation soapAction="urn:MyWebService#getXML"/> 
    <input> 
    <soap:body use="literal"/> 
    </input> 
    <output> 
    <soap:body use="literal"/> 
    </output> 
</operation> 

</binding> 
0

En el pasado he tenido problemas haciendo que .Net consuma servicios web creados con wsdl en formato rpc/literal. Intente convertir su WSDL a formato de documento/literal en su lugar y debería tener más suerte.

Cuestiones relacionadas