title: C# client authenticate PHP soap server
body: <p>I want to authenticate user using C# client, but nothing works. I'm new with visual studio so i don't know all functionality ;/ My basic button event:</p>
  
  <pre><code>        using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Net;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows.Forms;
  
      namespace WindowsFormsApplication1
      {
          public partial class Form1 : Form
          {
              public Form1()
              {
                  InitializeComponent();
              }
  
              private void button1_Click(object sender, EventArgs e)
              {
                  localhost.Calculator client = new localhost.Calculator();
  
                  string returnString = client.Average(10,8);
                  //System.Diagnostics.Debug.Write(rep);
                  label1.Text = returnString;
              }
          }
      }
  </code></pre>
  
  <p>My server.php file :</p>
  
  <pre><code>        &lt;?php
      ini_set("soap.wsdl_cache_enabled", "0");
  
      class Server{
  
          protected $class_name = '';
  
          public function __construct($class_name)
          {
              $this-&gt;class_name = $class_name;
          }
  
          public function authenticate ($username, $password)
          {
              if ($username != 'admin' &amp;&amp; $password != 'admin') return false;
              else return true;
          }
  
          public function log($method_name,$data)
          {
              $filename = 'log.txt';
              $handle = fopen($filename, 'a+');
              fwrite($handle, date("l dS of F Y h:i:s A").' - '.$_SERVER['REMOTE_ADDR']."\r\n".$method_name."\r\n".print_r($data,true));
              fclose($handle);
          }
  
          public function __call($method_name, $parameters)
          {
              $this-&gt;log($method_name,$parameters); //  log
  
              if(!$this-&gt;authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))
              {
  
              }
              else
              {
                  if(!method_exists($this-&gt;class_name, $method_name ))
                      return 'Method '.$method_name.' not found'; // methot exist check
  
                  return call_user_func_array(
                          array($this-&gt;class_name, $method_name ),
                          $parameters
                  ); //call method    
              }
          }
      }
  
  
      class Calculator {
          public function Average ($parameters)
          {
              $num1 = $parameters-&gt;num1;
              $num2 = $parameters-&gt;num2;
  
              return self::AverageResponse(($num1 + $num2) / 2);
          }
  
          public function AverageResponse ($message)
          {
              return ['Result' =&gt; $message];
          }
  
          public function Minus ($parameters)
          {
              $num1 = $parameters-&gt;num1;
              $num2 = $parameters-&gt;num2;
  
              return self::MinusResponse($num1 - $num2);
          }
  
          public function MinusResponse ($message)
          {
              return ['Result' =&gt; $message];
          }
      }
  
      class in {
  
      }
  
      $Service = new Server('Calculator');
      $classmap=[
          'in' =&gt; 'in'
      ];
      $server = new SOAPServer('http://localhost:9080/soap-websiteservice-wsdl/Calculator.wsdl', array(
          'soap_version' =&gt; SOAP_1_2,
          'style' =&gt; SOAP_RPC,
          'use' =&gt; SOAP_LITERAL,
          'classmap'=&gt;$classmap
      ));
      $server-&gt;setObject($Service);
      //$server-&gt;setClass('Calculator');
      $server-&gt;handle();
  </code></pre>
  
  <p>Php client authentication works. Code:</p>
  
  <pre><code>    &lt;?php
      // client.php
      $options = array(
          'trace' =&gt; true,
          'login' =&gt; 'admin',
          'password' =&gt; 'admin'
      );
      $client = new SOAPClient('http://localhost:9080/soap-websiteservice-wsdl/server.php?wsdl', $options);
  
      echo "Average: \r\n";
      var_dump($client-&gt;Average(['num1' =&gt; 10, 'num2' =&gt; 6])-&gt;Result);
  
      echo "Minus: \r\n";
      var_dump($client-&gt;Minus(['num1' =&gt; 10, 'num2' =&gt; 6])-&gt;Result);
  </code></pre>
  
  <p>wsdl:</p>
  
  <pre><code>        &lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
      &lt;wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost:9080/soap-websiteservice-wsdl/Calculator" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Calculator" targetNamespace="http://localhost:9080/soap-websiteservice-wsdl/Calculator"&gt;
        &lt;wsdl:types&gt;
          &lt;xsd:schema targetNamespace="http://localhost:9080/soap-websiteservice-wsdl/Calculator"&gt;
            &lt;xsd:element name="Average"&gt;
              &lt;xsd:complexType&gt;
                &lt;xsd:sequence&gt;
                  &lt;xsd:element name="num1" type="xsd:int" /&gt;
                  &lt;xsd:element name="num2" type="xsd:int"&gt;&lt;/xsd:element&gt;
                &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
            &lt;/xsd:element&gt;
            &lt;xsd:element name="AverageResponse"&gt;
              &lt;xsd:complexType&gt;
                &lt;xsd:sequence&gt;
                  &lt;xsd:element name="Result" type="xsd:string"/&gt;
                &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
            &lt;/xsd:element&gt;
  
            &lt;xsd:complexType name="AverageRequestType"&gt;
              &lt;xsd:sequence&gt;
                  &lt;xsd:element name="num1" type="xsd:int"&gt;&lt;/xsd:element&gt;
                  &lt;xsd:element name="num2" type="xsd:int"&gt;&lt;/xsd:element&gt;
              &lt;/xsd:sequence&gt;
            &lt;/xsd:complexType&gt;
            &lt;xsd:element name="Minus"&gt;
              &lt;xsd:complexType&gt;
                  &lt;xsd:sequence&gt;
  
                      &lt;xsd:element name="num1" type="xsd:int"&gt;&lt;/xsd:element&gt;
                      &lt;xsd:element name="num2" type="xsd:int"&gt;&lt;/xsd:element&gt;
                  &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
            &lt;/xsd:element&gt;
            &lt;xsd:element name="MinusResponse"&gt;
              &lt;xsd:complexType&gt;
                  &lt;xsd:sequence&gt;
  
                      &lt;xsd:element name="Result" type="xsd:string"&gt;&lt;/xsd:element&gt;
                  &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
            &lt;/xsd:element&gt;
            &lt;xsd:element name="AverageFault"&gt;
              &lt;xsd:complexType&gt;
                  &lt;xsd:sequence&gt;
  
                      &lt;xsd:element name="AverageFault" type="xsd:string"&gt;&lt;/xsd:element&gt;
                  &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
            &lt;/xsd:element&gt;
            &lt;xsd:element name="AverageFault1"&gt;
              &lt;xsd:complexType&gt;
                  &lt;xsd:sequence&gt;
  
                      &lt;xsd:element name="AverageFault" type="xsd:string"&gt;&lt;/xsd:element&gt;
                  &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
            &lt;/xsd:element&gt;
          &lt;/xsd:schema&gt;
        &lt;/wsdl:types&gt;
        &lt;wsdl:message name="AverageRequest"&gt;
          &lt;wsdl:part element="tns:Average" name="parameters"/&gt;
        &lt;/wsdl:message&gt;
        &lt;wsdl:message name="AverageResponse"&gt;
          &lt;wsdl:part element="tns:AverageResponse" name="parameters"/&gt;
        &lt;/wsdl:message&gt;
        &lt;wsdl:message name="MinusRequest"&gt;
          &lt;wsdl:part name="parameters" element="tns:Minus"&gt;&lt;/wsdl:part&gt;
        &lt;/wsdl:message&gt;
        &lt;wsdl:message name="MinusResponse"&gt;
          &lt;wsdl:part name="parameters" element="tns:MinusResponse"&gt;&lt;/wsdl:part&gt;
        &lt;/wsdl:message&gt;
        &lt;wsdl:message name="AverageFault"&gt;
          &lt;wsdl:part name="parameters" element="tns:AverageFault"&gt;&lt;/wsdl:part&gt;
        &lt;/wsdl:message&gt;
        &lt;wsdl:message name="AverageFault1"&gt;
          &lt;wsdl:part name="parameters" element="tns:AverageFault1"&gt;&lt;/wsdl:part&gt;
        &lt;/wsdl:message&gt;
        &lt;wsdl:portType name="Calculator"&gt;
          &lt;wsdl:operation name="Average"&gt;
            &lt;wsdl:input message="tns:AverageRequest"/&gt;
            &lt;wsdl:output message="tns:AverageResponse"/&gt;
  
              &lt;/wsdl:operation&gt;
          &lt;wsdl:operation name="Minus"&gt;
              &lt;wsdl:input message="tns:MinusRequest"&gt;&lt;/wsdl:input&gt;
              &lt;wsdl:output message="tns:MinusResponse"&gt;&lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
        &lt;/wsdl:portType&gt;
        &lt;wsdl:binding name="CalculatorSOAP" type="tns:Calculator"&gt;
          &lt;soap:binding style="document"
              transport="http://schemas.xmlsoap.org/soap/http" /&gt;
          &lt;wsdl:operation name="Average"&gt;
              &lt;soap:operation
                  soapAction="http://localhost:9080/soap-websiteservice-wsdl/Calculator/NewOperation" /&gt;
              &lt;wsdl:input&gt;
                  &lt;soap:body use="literal" /&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output&gt;
                  &lt;soap:body use="literal" /&gt;
              &lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
          &lt;wsdl:operation name="Minus"&gt;
              &lt;soap:operation
                  soapAction="http://localhost:9080/soap-websiteservice-wsdl/Calculator/Minus" /&gt;
              &lt;wsdl:input&gt;
                  &lt;soap:body use="literal" /&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output&gt;
                  &lt;soap:body use="literal" /&gt;
              &lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
        &lt;/wsdl:binding&gt;
        &lt;wsdl:service name="Calculator"&gt;
          &lt;wsdl:port binding="tns:CalculatorSOAP" name="CalculatorSOAP"&gt;
            &lt;soap:address location="http://localhost:9080/soap-websiteservice-wsdl/server.php"/&gt;
          &lt;/wsdl:port&gt;
        &lt;/wsdl:service&gt;
      &lt;/wsdl:definitions&gt;
  </code></pre>