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都是一样的访问的结果,求解。
写的代码和范例一样,就是访问不出结果。

解决方案 »

  1.   

    http://localhost:8989/weather?wsdl
    check一下
      

  2.   

    参考
    https://stackoverflow.com/questions/2083500/java-using-endpoint-to-publish-webservice-to-tomcat-server/2083707#2083707
      

  3.   


    试过了,显示This XML file does not appear to have any style information associated with it. The document tree is shown below.
      

  4.   


    看了下 这个是用tomcat容器的,有区别啊
      

  5.   

    我在本地跑了一下你的代码,访问http://localhost:8989/weather?wsdl没有任何问题
    jdk1.8.0_171检查一下你本地是否有对端口的屏蔽。或者换成8080或者80端口试一下。
      

  6.   

    也显示这个警告
    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    但是这个下面显示正确的wsdl内容。
      

  7.   

    但是显示的namespace有点奇怪,调用的时候要注意一下。
    <xsd:import namespace="http://temp/" schemaLocation="http://localhost:8989/weather?xsd=1"></xsd:import>
      

  8.   

    OK,重现了你的问题。
    我查一下,先看一下这个
    https://stackoverflow.com/questions/21177387/caution-provisional-headers-are-shown-in-chrome-debugger
      

  9.   

    我试了一下,没找到显示的方法,貌似不支持http列出所有的服务?
    如果客户端调用没问题的话,应该是发布成功了。这个文章或许可以解决你的问题
    https://stackoverflow.com/questions/20802335/endpoint-publish-for-rest-web-services
      

  10.   

    貌似是JDK版本问题,参考我参与的这个帖子
    用jdk1.7.0_71可以https://bbs.csdn.net/topics/392406467
      

  11.   

    应该是jdk版本的问题,我用你代码1.7的可以,1.8的就需要在发布地址后面加?wsdl 并且访问地址也加?wsdl  才能访问到