lianyang506277 2017-03-08 02:38 采纳率: 10%
浏览 1028

请问为什么我发布成功了浏览器访问不到

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface WebServiceI {

@WebMethod
String sayHello(String name);

@WebMethod
String save(String name,String pwd);

}

import javax.jws.WebService;

@WebService(targetNamespace = "org.coderecord.blog")
public class WebServiceImpl implements WebServiceI {

@Override
public String sayHello(String name) {
    System.out.println("webservice sayHello"+name);
    return "sayHello "+name;
}

@Override
public String save(String name, String pwd) {
    System.out.println("webservice save"+ name+","+pwd);
    return "save Success";
}

}

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.xml.ws.Endpoint;

@WebListener
public class WebServicePublishListener implements ServletContextListener {

@Override
public void contextDestroyed(ServletContextEvent sce) {
    // TODO Auto-generated method stub

}

@Override
public void contextInitialized(ServletContextEvent sce) {
    String address = "http://localhost:8889/Service/WebserviceTest";
    Endpoint.publish(address , new WebServiceImpl());
    System.out.println("使用WebServicePublishListener发布webservice成功!");

}

}

  • 写回答

2条回答 默认 最新

  • hit、run 2017-03-08 05:18
    关注

    发布webservice
    public class WebServicePublicsh {
    public static void main(String[] args) {
    //1.JAXWS规范的服务工厂bean
    JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();
    //2.设置发布地址
    bean.setAddress("http://localhost:12345/weather");
    //3.设置服务类
    bean.setServiceBean(new WeatherService());
    //4.发布
    bean.create();
    }
    }

    测试地址:http://localhost:12345/weather?wsdl,就可以看到访问结果为xml格式

    你访问地址加了?wsdl了没

    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号