java调用获取天气情况的webservice接口总是报错不知其原因 求指导!谢谢

一路前行java 发布于 2016/12/07 09:27
阅读 827
收藏 0

调取一个获取天气情况的服务 就是报错误 我找很久都不知道起原因 求解 谢谢 (代码附上)

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;


public class WebserviceTest {
static Logger logger = Logger.getLogger(WebserviceTest.class.getName());
 public static void main(String[] args) throws  ServiceException, MalformedURLException{
// TODO Auto-generated method stub


 try {
String ur="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl";
String namespace="http://WebXml.com.cn/getWeatherbyCityName";
String tt="成都";
QName q=new QName(namespace,"theCityName");
Service ce=new Service();
Call cal=(Call)ce.createCall();
cal.setOperationName(q);
cal.setTargetEndpointAddress(new URL(ur));
        cal.setUseSOAPAction(true); 
        cal.setSOAPActionURI("http://WebXml.com.cn/getWeatherbyCityName");
        cal.addParameter("theCityName",org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
       // cal.addParameter(tt, org.apache.axis.Constants.XSD_LONG,ParameterMode.IN);
        cal.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING);
String ssss=(String)cal.invoke(namespace,new Object[]{tt});
//System.out.println("1111"+result);
System.out.println(ssss);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.err.println(""+e.toString());
}
异常 ::::::

AxisFault
 faultCode: {http://xml.apache.org/axis/}HTTP
 faultSubcode: 
 faultString: (400)Bad Request
 faultActor: 
 faultNode: 
 faultDetail: 
{}:return code:  400


{http://xml.apache.org/axis/}HttpErrorCode:400


(400)Bad Request
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:2391)
at WebserviceTest.main(WebserviceTest.java:30)
(400)Bad Request

现在 出现了又出现了一个异常 我不知道是咋回事求指导(源码)

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.TypeMapping;
import org.apache.axis.encoding.TypeMappingRegistry;


public class WebserviceTest {
static Logger logger = Logger.getLogger(WebserviceTest.class.getName());
 public static void main(String[] args) throws  ServiceException, MalformedURLException{
// TODO Auto-generated method stub


 try {
String ur="http://Ws.webxml.com.cn/WebServices/WeatherWebService.asmx";
String namespace="http://WebXml.com.cn/";
String tt="成都";
QName q=new QName(namespace,"getWeatherbyCityName");
Service ce=new Service();
Call cal=(Call)ce.createCall();
cal.setOperationName(q);
cal.setTargetEndpointAddress(new URL(ur));
        cal.setUseSOAPAction(true); 
        cal.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING);
        //cal.addParameter(new QName("http://WebXml.com.cn/","theCityName"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        cal.addParameter(new QName("http://WebXml.com.cn/","theCityName"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        cal.setSOAPActionURI("http://WebXml.com.cn/getWeatherbyCityName");
        Object[] oo=new Object[]{tt};
String ssss=(String)cal.invoke(oo);
System.out.println("1111"+ssss);
System.out.println(ssss);
} catch (RemoteException e) {

e.printStackTrace();
System.err.println(""+e.toString());
}












/*

List<Service> ll=new ArrayList<Service>();
for(Service tt:ll){
System.out.println(tt);
}
*/


/*HttpURLConnection connection=null;
try {
connection = (HttpURLConnection) uu.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
connection.setRequestProperty("Content-type", "application/soap+xml; charset=utf-8");

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}  */












}


}

异常

2016-12-7 10:39:06 org.apache.axis.client.Call invoke
严重: Exception:
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was try
ing to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at WebserviceTest.main(WebserviceTest.java:32)
AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in someth
ing it was trying to deserialize.
 faultActor: 
 faultNode: 
 faultDetail: 
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which
 is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at WebserviceTest.main(WebserviceTest.java:32)


{http://xml.apache.org/axis/}hostname:PC-201608130251


org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was try
ing to deserialize.
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.client.Call.invoke(Call.java:2470)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at WebserviceTest.main(WebserviceTest.java:32)
Caused by: org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something
 it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
... 3 more
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was try
ing to deserialize.



加载中
0
乾坤摄
乾坤摄
http://www.webxml.com.cn/h/3644654A774B73394277303D.aspx 不是说域名调整了吗?
一路前行java
我也看过啊说域名调整了 不是我上面写的那个吗?我试看你给我这个呢! 谢谢
0
liu13430
liu13430
https://my.oschina.net/liu13430/blog/373940
liu13430
liu13430
这里有例子。
返回顶部
顶部