Failure to communicate with PHP webservice

3

I'm trying to access a PHP webservice through an ASP.NET application

ccbusca.pesqwebservice client = new ccbusca.pesqwebservice();
client.Url = "http://www.ccbusca.com.br/webservice.php";

ret = client.ws_pesqcpf("VISUALFIX01", "XXXX@", "302X");

When I run this code snippet, I'm getting this error:

  

Additional information: The customer found the content type of   'text / html; charset = UTF-8, text / xml; charset = UTF-8 ', but   I was expecting 'text / xml'.

The webservice response came right below in the same error message.

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:ws_pesqcpfResponse xmlns:ns1="urn:cbuscaws"><return xsi:type="xsd:string"><?xml version="1.0" encoding="utf-8"?>
<xml>
  <ocorrencia>
    <codocor>0</codocor>
    <msgocor>encontrado</msgocor>
  </ocorrencia>
  <cadastro>
    <cpf>XXX</cpf>
    <nome>OTAVIO</nome>
...

I also tried to make the request using HttpWebRequest, but without success.

string url = "http://www.ccbusca.com.br/webservice.php/ws_pesqcpf?usr=VISUALFIX01&pwd=visualfix2016@&cpf=30264304802";

            System.Net.WebRequest request;
            System.Net.WebResponse response;
            System.IO.Stream dataStream;
            System.IO.StreamReader reader;
            string responseFromServer;

            try
            {
                // Create a request for the URL.
                request = System.Net.WebRequest.Create(url);
                // If required by the server, set the credentials.
                request.Credentials = System.Net.CredentialCache.DefaultCredentials;
                // Get the response.
                response = request.GetResponse();
                // Display the status.
                Console.WriteLine(((System.Net.HttpWebResponse)response).StatusDescription);
                if(((System.Net.HttpWebResponse)response).StatusCode == System.Net.HttpStatusCode.OK)
                {
                    // Get the stream containing content returned by the server.
                    dataStream = response.GetResponseStream();
                    // Open the stream using a StreamReader for easy access.
                    reader = new System.IO.StreamReader(dataStream);
                    // Read the content.
                    responseFromServer = reader.ReadToEnd();
                    // Clean up the streams and the response.
                    reader.Close();
                    response.Close();
                }
            }
            finally
            {
                request = null;
                response = null;
                dataStream = null;
                reader = null;
            }

In this way, I could not see the data. I returned an HTML code from a page that might be a default message for error 404.

Primary URL: link Method: ws_pesqcpf Parameters: usr, pwd, and cpf

So, should not my URL be this? link

Querying via SoapUI works. I can see the data.

    
asked by anonymous 03.02.2017 / 04:11

1 answer

0

This can happen when the webservice generates an error and instead of sending in xml format it sends in html format that would be the page with the error. The webservice client in .Net always expects an xml response and if it comes html it throws that error. It controls this by the HTTP header that has the content-type that identifies the document type, if you use some tool to intercept that http message like Fiddler for example you can see the http packet of the response and you will see that the content-type is coming as text / html.

In this link link has an explanation about it and might help.

    
04.02.2017 / 20:23