Communication failure with PHP webservice

Asked

Viewed 1,071 times

4

I am 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");

While running this code snippet, I am getting this error:

Additional information: Customer found content type text/html response; charset=UTF-8,text/xml; charset=UTF-8', but expected 'text/xml'.

The response from the webservice came correctly just 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 visualize the data. It returned me an HTML code from a page that might be a standard message for error 404.

URL Home: http://www.ccbusca.com.br/webservice.php Method: ws_pesqcpf Parameters: usr, pwd and Cpf

Therefore, my URL should not be this? http://www.ccbusca.com.br/webservice.php/ws_pesqcpf?usr=VISUALFIX&pwd=xxxx@&cpf=302X

Performing the query via Soapui works. I can see the data.

  • The return seems to be wrong from the web service. Check out http://stackoverflow.com/questions/115319/how-can-the-error-client-found-responsontent-type-of-text-html-be-interp

  • @Gabrielheming doesn’t seem to be the error of the webservice, since other applications use this webservice. It seems to me that the return of the webservice in PHP is really TEXT/HTML. I believe that in this frequency I should use Httpwebrequest to get the return, but when trying to access, I got error 411.

1 answer

1

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 to html it throws this 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 this http message like Fiddler for example you can see the http package of the response and see that the content-type is coming as text/html.

At this link https://stackoverflow.com/questions/115319/how-can-the-error-client-found-response-content-type-of-text-html-be-interp has an explanation about and may help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.