[英]SOAP request using Apache HttpClient
I'm trying to make a SOAP request to URL http://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry but i got an error: 我正在尝试向URL http://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry发出SOAP请求,但出现错误:
<?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. 如果我在浏览器上调用URI,它将起作用。 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.
System.InvalidOperationException:超时已过期。 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. 与客户端相关的异常看起来更像是后端异常(服务方似乎无法连接到SQL数据库)。 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.
我在帖子中运行了代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.