weservice调用Server returned HTTP response code: 500 for URL

java_news 2010-08-25 03:02:14
比较急,麻烦帮忙看看。谢谢!


自己写了个xfire+java的webservice,部署成功,在服务器端访问http://localhost:8000/test/service/UserService?wsdl
成功显示:
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="http://webservice.test.com.cn" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:tns="http://webservice.test.com.cn" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
- <wsdl:types>
- <xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://webservice.test.com.cn" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
.........




但是写了个客户端调用http://localhost:8000/test/service/UserService报错:
java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8090/test/service/UserService
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at client.ClientMain.doPost(ClientMain.java:43)
at client.ClientMain.sendInformation(ClientMain.java:77)
at client.ClientMain.main(ClientMain.java:89)




客户端代码:
HttpURLConnection connection = null;
String result ="http://localhost:8090/FAP/service/UserService";
URL url = new URL(result);
connection = (HttpURLConnection)url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
...全文
4298 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
crystal92339 2012-08-15
  • 打赏
  • 举报
回复
楼上的真心是经典啊!多谢了!
忧云 2012-05-05
  • 打赏
  • 举报
回复
我也遇到上面的问题,纠结了好久,网上讲的都做了但都不行,最后下了源码,查到里面的源码去,发现,axis在解析时要用到wsdl来进行parse才能正确转换,我就在后面添加了一行代码:
call.setEncodingStyle(wsdl);
然后就都可以了,参数wsdl是你访问wsdl的地址,有这个问题的人可以试试,要真可以记得谢我哟.
浪里个郎 2011-06-25
  • 打赏
  • 举报
回复
楼主说的好啊,我也遇到这样的问题,试试楼住的方法
java_news 2010-10-15
  • 打赏
  • 举报
回复
加上这几句
call.addParameter("name", org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
---这句是要指定你传的参数名要跟他那边需要的参数名称一样
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
---------这句是指定你参数的类型
call.setUseSOAPAction(true);
zhaijiji 2010-10-12
  • 打赏
  • 举报
回复
楼主怎么解决的?我也碰到这个问题
java_news 2010-08-25
  • 打赏
  • 举报
回复
加上这几句就对了。
call.addParameter("name", org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
java_news 2010-08-25
  • 打赏
  • 举报
回复
String endpoint = "http://localhost:8000/test/service/UserService";
org.apache.axis.client.Service service = new org.apache.axis.client.Service();
org.apache.axis.client.Call call = (org.apache.axis.client.Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("userToXml");
String name = "name";
int age = 11;
String res=(String)call.invoke(new Object[]{name,age});
System.out.print(res);


报错:Exception in thread "main" AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server
faultSubcode:
faultString: For input string: ""
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:For input string: ""
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
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:1812)
at client.ClientMain.main(ClientMain.java:104)

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

For input string: ""
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
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:1812)
at client.ClientMain.main(ClientMain.java:104)
阿_布 2010-08-25
  • 打赏
  • 举报
回复

String endpoint = "http://localhost:8090/FAP/service/UserService";
org.apache.axis.client.Service service = new org.apache.axis.client.Service();
org.apache.axis.client.Call call = (org.apache.axis.client.Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("方法名");
String res=(String)call.invoke(new Object[]{"参数","参数"});
System.out.print(res);

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧