调取一个获取天气情况的服务 就是报错误 我找很久都不知道起原因 求解 谢谢 (代码附上)
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.
http://www.webxml.com.cn/h/3644654A774B73394277303D.aspx不是说域名调整了吗?我也看过啊说域名调整了不是我上面写的那个吗?我试看你给我这个呢!谢谢https://my.oschina.net/liu13430/blog/373940这里有例子。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。