title: ASP.NET/C# client to consume a PHP/MYSQL web service (WSDL)
body: <p>I am trying to access a webservice (two files below). The client is using ASP.NET/C# for their web architecture. I can add the web reference but somehow I cannot generate a proxy class for the wsdl file. The aim is to use the function in the server.php file so that I can use the xmlstring to display the data on the ASP.NET website. Any help would be very appreciated. Many Thanks</p>
  
  <hr>
  
  <p>server.php file. This file has a php function which extracts data from a mysql db and the function returns the data as an XML string.</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?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 = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n";
  $xmlstring.= "&lt;videogames&gt;";
  
  while ($row = mysql_fetch_array($sqlresult))
  {
      $xmlstring .= "\t&lt;game&gt;\r\n";
          $xmlstring .= "\t\t&lt;gametitle&gt;" .$row["gametitle"]. "&lt;/gametitle&gt;\r\n";
          $xmlstring .= "\t\t&lt;genre&gt;" .$row["genre"]. "&lt;/genre&gt;\r\n";
          $xmlstring .= "\t\t&lt;year&gt;" .$row["year"]. "&lt;/year&gt;\r\n";
          $xmlstring .= "\t\t&lt;platform&gt;" .$row["platform"]. "&lt;/platform&gt;\r\n";
          $xmlstring .= "\t\t&lt;agerating&gt;" .$row["agerating"]. "&lt;/agerating&gt;\r\n";
          $xmlstring .= "\t\t&lt;price&gt;" .$row["price"]. "&lt;/price&gt;\r\n";
      $xmlstring .= "\t&lt;/game&gt;\r\n";
  }
  
  $xmlstring.= "&lt;/videogames&gt;";
  
  //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-&gt;addFunction("getXML");
  
  //ACTIVATE THE SOAP HANDLER
  $server-&gt;handle();
  
  ?&gt;
  </code></pre>
  
  <p>This is the WSDL file linked to the server.php file.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version ='1.0' encoding ='UTF-8' ?&gt;
  
  &lt;!-- ====================== DEFINITIONS ====================== --&gt;
  
  &lt;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"&gt;
  
  &lt;!-- ====================== TYPES ============================ --&gt;
  &lt;!-- No need for type definitions as only xsd built-in ======= --&gt; 
  &lt;!-- data types are used                                       --&gt;
  &lt;!-- ========================================================= --&gt;
  
  &lt;!-- ====================== MESSAGE ========================== --&gt;
  
  &lt;message name="getXML_Request"&gt;
  &lt;part name="input" /&gt;
  &lt;/message&gt;
  
  &lt;message name="getXML_Response"&gt;
  &lt;part name="xmlString" type="xsd:string"/&gt;
  &lt;/message&gt;
  
  &lt;!-- ====================== PORT TYPE ============================ --&gt;
  
  &lt;portType name="myWebService_PortType"&gt;
  
  &lt;operation name="getXML"&gt;
     &lt;input  message="tns:getXML_Request"/&gt;
     &lt;output message="tns:getXML_Response"/&gt;
  &lt;/operation&gt;
  
  &lt;/portType&gt;
  
  &lt;!-- ======================= BINDING ============================= --&gt;
  
  &lt;binding name="myWebService_Binding" type="tns:myWebService_PortType"&gt;
  &lt;soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
  
  &lt;operation name="getXML"&gt;
     &lt;input&gt;
       &lt;soap:body use="literal"/&gt;
     &lt;/input&gt;
     &lt;output&gt;
       &lt;soap:body use="literal"/&gt;
     &lt;/output&gt;
  &lt;/operation&gt;
  
  &lt;/binding&gt;
  
  &lt;!-- ======================= SERVICE ============================= --&gt;
  
  &lt;service name="myWebService_Service"&gt;
  &lt;port name="myWebService_Port" binding="tns:myWebService_Binding"&gt;
      &lt;soap:address location="http://cet-apache-04.cet.bolton.ac.uk/student/mib1bee/CST3017/assignment/scenario1/server.php"/&gt;
  &lt;/port&gt;
  &lt;/service&gt;
  
  &lt;/definitions&gt;
  </code></pre>