有关Webservice中Endpoint.publish的问题

老笨黄 2018-06-20 05:49:12

public interface WeatherInterface {
//天气查询
public String queryWeather(String cityName);
}

@WebService//@WebService表示该类是一个服务类需要发布其中的public方法
public class WeatherInterfaceImpl implements WeatherInterface {

public String queryWeather(String cityName) {
System.out.println("from client..."+cityName);
String weather = "晴";
System.out.println("to client..."+weather);
return weather;
}
}

public class WeatherServer {
public static void main(String[] args) {
//Endpoint发布服务
//参数解释
//1.address - 服务地址
//2.implementor - 实现类
Endpoint.publish("http://localhost:8989/weather",new WeatherInterfaceImpl());
System.out.println("发布成功!");
}
}


执行代码显示发布成功后,浏览器端访问显示 错误码 324 (net::ERR_EMPTY_RESPONSE)。
地址写127.0.0.1,beiji ip都是一样的访问的结果,求解。
写的代码和范例一样,就是访问不出结果。
...全文
1435 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_39013701 2019-02-10
  • 打赏
  • 举报
回复
应该是jdk版本的问题,我用你代码1.7的可以,1.8的就需要在发布地址后面加?wsdl 并且访问地址也加?wsdl 才能访问到
stacksoverflow 2018-06-29
  • 打赏
  • 举报
回复
貌似是JDK版本问题,参考我参与的这个帖子
用jdk1.7.0_71可以

https://bbs.csdn.net/topics/392406467
stacksoverflow 2018-06-21
  • 打赏
  • 举报
回复
我试了一下,没找到显示的方法,貌似不支持http列出所有的服务?
如果客户端调用没问题的话,应该是发布成功了。

这个文章或许可以解决你的问题
https://stackoverflow.com/questions/20802335/endpoint-publish-for-rest-web-services
stacksoverflow 2018-06-21
  • 打赏
  • 举报
回复
OK,重现了你的问题。
我查一下,先看一下这个
https://stackoverflow.com/questions/21177387/caution-provisional-headers-are-shown-in-chrome-debugger
老笨黄 2018-06-21
  • 打赏
  • 举报
回复
引用 7 楼 stacksoverflow 的回复:
但是显示的namespace有点奇怪,调用的时候要注意一下。
<xsd:import namespace="http://temp/" schemaLocation="http://localhost:8989/weather?xsd=1"></xsd:import>


正常访问地址,应该显示这样格式的:
stacksoverflow 2018-06-21
  • 打赏
  • 举报
回复
但是显示的namespace有点奇怪,调用的时候要注意一下。
<xsd:import namespace="http://temp/" schemaLocation="http://localhost:8989/weather?xsd=1"></xsd:import>
stacksoverflow 2018-06-21
  • 打赏
  • 举报
回复
也显示这个警告
This XML file does not appear to have any style information associated with it. The document tree is shown below.
但是这个下面显示正确的wsdl内容。
stacksoverflow 2018-06-21
  • 打赏
  • 举报
回复
我在本地跑了一下你的代码,访问http://localhost:8989/weather?wsdl没有任何问题
jdk1.8.0_171

检查一下你本地是否有对端口的屏蔽。

或者换成8080或者80端口试一下。

老笨黄 2018-06-20
  • 打赏
  • 举报
回复
引用 2 楼 stacksoverflow 的回复:
参考
https://stackoverflow.com/questions/2083500/java-using-endpoint-to-publish-webservice-to-tomcat-server/2083707#2083707


看了下 这个是用tomcat容器的,有区别啊
老笨黄 2018-06-20
  • 打赏
  • 举报
回复
引用 1 楼 stacksoverflow 的回复:
http://localhost:8989/weather?wsdl
check一下


试过了,显示This XML file does not appear to have any style information associated with it. The document tree is shown below.
stacksoverflow 2018-06-20
  • 打赏
  • 举报
回复
参考
https://stackoverflow.com/questions/2083500/java-using-endpoint-to-publish-webservice-to-tomcat-server/2083707#2083707
stacksoverflow 2018-06-20
  • 打赏
  • 举报
回复
http://localhost:8989/weather?wsdl
check一下

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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