I'm trying to make a SOAP request to URL http://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry but i got an error:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Server was unable
to process request. ---> System.InvalidOperationException: Timeout
expired. The timeout period elapsed prior to obtaining a connection
from the pool. This may have occurred because all pooled connections
were in use and max pool size was reached.
at WebServicex.GlobalWeather.GetCitiesByCountry(String CountryName)
--- End of inner exception stack trace ---
</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
If i call the URI on browser, it works. I think it's missing something on my code.
Here is what i'm doing:
public static String doSOAPPost() throws IOException{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost =
new HttpPost("http://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry");
httpPost.addHeader("content-type", "text/xml");
StringBuffer buffer = new StringBuffer();
buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
buffer.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
buffer.append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
buffer.append("<soap:Body>");
buffer.append("<GetCitiesByCountry xmlns=\"http://www.webserviceX.NET\">");
buffer.append("<CountryName>Brazil</CountryName>");
buffer.append("</GetCitiesByCountry>");
buffer.append("</soap:Body>");
buffer.append("</soap:Envelope>");
StringEntity lEntity = new StringEntity(buffer.toString());
httpPost.setEntity(lEntity);
HttpResponse lHttpResponse = httpClient.execute(httpPost);
if (lHttpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK){
throw new RuntimeException("HTTP problems posting method " +
lHttpResponse.getStatusLine().getReasonPhrase());
}
return EntityUtils.toString(lHttpResponse.getEntity());
}
How can i fix this error? What is wrong?
Thank in advance.
I just executed your code, without modification, and I got back this response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET">
<GetCitiesByCountryResult>
<NewDataSet>
<Table>
<Country>Brazil</Country>
<City>Conceicao Do Araguaia</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Afonsos Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Anapolis Braz-Afb</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Aracaju Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Alta Floresta Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Benjamin Constant</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Belem Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Bage Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Belo Horizonte Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Curitiba</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Barbacena</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Brasilia Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Bauru</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Boa Vista Aeropor-To</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Barra Do Garcas</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Belo Horizonte</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Campo Grande Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Maranhao / Carolina Airport</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Porto Alegre</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Campos</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Corumba</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Curitiba Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Caravelas Aeropor-To</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Cuiaba Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Cruzeiro Do Sul</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Presidente Prudente</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Eduardo Gomes International</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Jacareacanga</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>S. P. Aldeia Aerodrome</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Foz Do Iguacu Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Florianopolis Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Fernando De Noronha</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Fortaleza Aeropor-To</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Gama</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Galeao</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Goiania Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Guarulhos Civ / Mil</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Guaratingueta</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Altamira</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Itaituba</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Ilheus Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Imperatriz</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Juiz De Fora</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Joao Pessoa</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Rio / Jacarepagua</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Campina Grande</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Campinas Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Londrina Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Bom Jesus Da Lapa</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Maraba</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Macae</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Maringa</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Montes Claros</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Manaus Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Maceio Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Macapa</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Mocoro / 17 Rosado</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Marte Civ / Mil</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Manicore</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Natal Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Oiapoque</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Porto Alegre Aero-Porto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Parnaiba Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Pocos De Caldas</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Passo Fundo</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Paranagua</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Pelotas</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Petrolina Aeropor-To</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Porto Nacional Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Ponta Pora Aeropor-To</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Porto Velho Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Vitoria Da Conquista</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Rio Branco</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Recife Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Rio De Janeiro Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Resende</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Sao Carlos</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Santa Cruz Aeropor-To</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Sao Jose Dos Campo</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Sao Luiz Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Santa Maria Aero-Porto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Santarem-Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Sao Paulo Aeropor-To</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Santos Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Salvador Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Teresina Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Tefe</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Tarauaca</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Tabatinga</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Tucurui</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Sao Gabriel Da Cachoeira</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Paulo Afonso</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Uruguaiana Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Uberaba</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Vilhena Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Vitoria Aeroporto</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Xavantina</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Iauarete</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Pirassununga</City>
</Table>
<Table>
<Country>Brazil</Country>
<City>Barcelos</City>
</Table>
</NewDataSet>
</GetCitiesByCountryResult>
</GetCitiesByCountryResponse>
</soap:Body>
</soap:Envelope>
The error message:
System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
looks more like a backend exception (seems like the servier couldn't connect to an SQL database) than an exception related to the client. So it seems the server had a problem when you were trying your call .
Just one advice though, replace this:
HttpPost httpPost = new HttpPost(
"http://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry");
with this:
HttpPost httpPost = new HttpPost(
"http://www.webservicex.net/globalweather.asmx");
It is likely a temporary problem with the service on the server. I ran the code in the post just fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.