title: How to access a PHP Web Service from ASP.Net?
body: <p>I am trying use a web service in a C# ASP.Net Web Application. The service is built in PHP  and is located on some remote server not under my control so I cant modify it to add meta data or something else into it.</p>
  
  <p>When I use the "Add Web Reference" option in Visual Studio 2008,
  I receive the following error:</p>
  
  <blockquote>
    <p>The HTML document does not contain Web
    service discovery information.</p>
  </blockquote>
  
  <p>while trying to add the following web service.</p>
  
  <p><a href="https://subreg.forpsi.com/robot2/subreg_command.php?wsdl" rel="nofollow noreferrer">https://subreg.forpsi.com/robot2/subreg_command.php?wsdl</a></p>
  
  <p>The web service functions are exposed and displayed in Visual Studio 2008. however i could not add the reference to it for use in ASP.Net Application.</p>
  
  <blockquote>
    <p>t3Service" Description</p>
    
    <p>Methods
    __construct ( ) </p>
    
    <p>create_contact ( ) </p>
    
    <p>get_contact ( ) </p>
    
    <p>get_domain_info ( ) </p>
    
    <p>get_last_error_code ( ) </p>
    
    <p>get_last_error_msg ( ) </p>
    
    <p>get_NSSET ( ) </p>
    
    <p>get_owner_mail ( ) </p>
    
    <p>login ( ) </p>
    
    <p>register_domain ( ) </p>
    
    <p>register_domain_with_admin_contacts (
    ) </p>
    
    <p>renew_domain ( ) </p>
    
    <p>request_sendmail ( ) </p>
    
    <p>send_auth_info ( ) </p>
    
    <p>transfer_domain ( )</p>
  </blockquote>
  
  <ol start="2">
  <li><p>I also tried the wsdl.exe method by retrieving the xml and copying it to a wsdl file and generating a proxy class. But the wsdl output contains warnings and the proxy class generated skips the exposed functions and generates something like this:</p>
  
  <p>// CODEGEN: The operation binding 'create_contact' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'get_contact' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'get_domain_info' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'get_last_error_code' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'get_last_error_msg' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'get_NSSET' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'get_owner_mail' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'send_auth_info' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'transfer_domain' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'request_sendmail' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'login' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'register_domain' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'register_domain_with_admin_contacts' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.
  // CODEGEN: The operation binding 'renew_domain' from namespace 'urn:t3' was ignored.  Each message part in an use=encoded message must specify a type.</p></li>
  </ol>
  
  <p>Edit:</p>
  
  <p>I tried this piece of code for my hand coded class.</p>
  
  <pre><code>public String makeWebRequest(String methodName)
          {
                // Create the web request  
                HttpWebRequest request = WebRequest.Create("https://subreg.forpsi.com/robot2/subreg_command.php/") as HttpWebRequest;  
                // Add authentication to request  
                request.Credentials = new NetworkCredential("foo@mydomain.com", "bar");
                request.Method = "POST";
                request.ContentType = "text/xml";
                request.Headers.Add("SOAPAction: https://subreg.forpsi.com/robot2/subreg_command.php/" + methodName);
  
              // Get response  
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)  
               {  
                 // Get the response stream  
                 StreamReader reader = new StreamReader(response.GetResponseStream());  
                 // Console application output  
                 //Console.WriteLine(reader.ReadToEnd());
                 return reader.ReadToEnd();
               }  
          }
  </code></pre>
  
  <p>But when I try to get response then it returns </p>
  
  <blockquote>
    <p>The remote server returned an error: (500) Internal Server Error.</p>
  </blockquote>