About WebService implementing a Web interface

Source: Internet
Author: User
Tags wsdl

Package service;

Import java.util.List;

Import Javax.jws.WebMethod;
Import Javax.jws.WebService;

/**
* @description Function Description:
* @author Author: Zhou Zhiwei
* @param parameters:
* @createdate Build Date: 2014-9-4 9:37:40
* @projectname Project Name: Spring_mvctype
* @packageclass Package and class name: Com.spring.mvc.service.connservice.java
*/

The first step is to create the Web interface first
@WebService
public interface Connservice {

@WebMethod
Public String stringlist ();

@WebMethod
Public List getlist ();

}

The second step is to implement this interface

Package Serviceimpl;

Import java.util.List;

Import Javax.jws.WebService;

Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.stereotype.Service;

Import Service.connservice;

Import Com.spring.mvc.jdbc.JdbcDao;

/**
* @description function Description:
* @author Author: Zhou Zhiwei
* @param parameter:
* @createdate Date established: 2014-9-4 am 9:38:31
* @projectname Project Name: Spring_mvctype
* @packageclass Package and class name: Com.spring.mvc.serviceimpl.connserviceimpl.java
*/
@WebService (endpointinterface= "Service.connservice")
@Service (value= "Connservice")
public class Connserviceimpl implements connservice{




@Autowired
Jdbcdao DAO;
@Override
/**
* @description function Description: WebService returns the list JSON result
* @author Author: Zhou Zhiwei
* @param parameters:
* @creat Edate Date established: 2014-9-4 morning 9:38:31
* @projectname project name: Spring_mvctype
* @packageclass Package and class name: Com.spring.mvc.serviceimpl.connserviceimpl.java
*/
public string stringlist () {
String sql = ' SELECT * from CS _contract t where t.id= ' 30053 ' ";
List List = Dao.querydata (sql);//Execute SQL


Net.sf.json.JSONArray jsonarray = Net.sf.json.JSONArray.fromObject (list); Convert result set to list JSON string

return jsonarray.tostring ();//to String type
}




/**
* @description Function Description: WebService returns the list result
* @author Author: Zhou Zhiwei
* @param parameters:
* @createdate Build Date: 2014-9-4 9:38:31
* @projectname Project Name: Spring_mvctype
* @packageclass Package and class name: Com.spring.mvc.serviceimpl.connserviceimpl.java
*/
Public List getlist () {

String sql = "SELECT * from Cs_contract t where t.id= ' 30053 '";
List List = Dao.querydata (SQL); Execute SQL
List Weblist=null;
for (int i = 0; i < list.size (); i++) {//The result set is a two-tier list so we have to loop a layer list
Weblist = (List) list.get (i);
}

return weblist; Return results list
}



}

The third step is to add the Server-ws.xml WebService configuration file but you have to import the Spring CXF jar Package

<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws= "Http://cxf.apache.org/jaxws"
xmlns:jaxrs= "Http://cxf.apache.org/jaxrs" xmlns:cxf= "Http://cxf.apache.org/core"
Xmlns:simple= "Http://cxf.apache.org/simple"
Xsi:schemalocation= "Http://cxf.apache.org/jaxws
Http://cxf.apache.org/schemas/jaxws.xsd
Http://cxf.apache.org/jaxrs
Http://cxf.apache.org/schemas/jaxrs.xsd
Http://cxf.apache.org/core
Http://cxf.apache.org/schemas/core.xsd
Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Http://cxf.apache.org/simple
Http://cxf.apache.org/schemas/simple.xsd "
Default-autowire= "ByName" default-lazy-init= "true" >

<!--import CXF Initial configuration--
<import resource= "Classpath:meta-inf/cxf/cxf.xml"/>
<import resource= "Classpath:meta-inf/cxf/cxf-servlet.xml"/>
<import resource= "Classpath:meta-inf/cxf/cxf-extension-soap.xml"/>




<!--testing the Web service Interface --

<!--This path is the path to the class--
<bean id= "Borrowere" class= "Serviceimpl.connserviceimpl"/>
<jaxws:endpoint id= "Webser" implementor= "#borrowere" address= "/webser"/>


</beans>

Fourth step in Applicationcontext.xml import server-ws.xml

<!--WebService configuration file--
<import resource= "Server-ws.xml"/>

Fifth step in the Web. XML Configuration WebService

<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

If you have a maven, you can download the jar package directly

<dependency>
<groupId>org.apache.servicemix.samples.cxf-wsdl-first</groupId>
<artifactId>wsdl-first-cxf-sa</artifactId>
<version>3.3.2</version>
<type>zip</type>
</dependency>

Sixth Step Release Project test if this page proves that your WebService interface has been configured successfully, if someone else wants to tune your interface, you just give him the server URL. HTTP://127.0.0.1:9090/SPRING_MVC/SERVICES/WEBSER?WSDL can be called directly on his local client interface.

Browser input http://127.0.0.1:9090/spring_mvc/services/webser?wsdl//webser for Interface name customization

Seventh step call Interface new Project

Just like this webservice interface is easy to fix ...

About WebService implementing a Web interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.