Developed using CXF WebService server side notes _

Developed using CXF WebService server side notes _

1, to achieve the functions:

To achieve the functionality is very simple server-side to provide a user password under the login name check services, as a String type of input parameters, the return value is String type, is indeed very simple, simply could not be more simple.

What is not here to explain the meaning of CXF, CXF Why should these academic problems, do not know the answer of their own to baidu and google to find out.

2, implementation steps:

Our web project from an empty to begin with, step by step shows how to perform and verify.

2.0 Preparing Files:

Download the release CXF file, download the address is http://cxf.apache.org/download.html, I downloaded the latest version is 2.2.7, unzipped directly into the apache-cxf-2.2.7/lib, the jar file in the directory stored separately and will be imported into the web project. A total of 66 files more then 26MB.

New web 2.1 project webproject, into the jar cxf file, and then modify the web.xml file:

<context-param>

<param-name> contextConfigLocation </ param-name>

<param-value> classpath *: application *. xml </ param-value>

</ Context-param>

<listener>

<listener-class>

org.springframework.web.context.ContextLoaderListener

</ Listener-class>

</ Listener>

<! - The first two on Needless to say, here is our concern CXF configuration ->

<servlet>

<servlet-name> CXFServlet </ servlet-name>

<servlet-class>

org.apache.cxf.transport.servlet.CXFServlet

</ Servlet-class>

<load-on-startup> 1 </ load-on-startup>

</ Servlet>

<servlet-mapping>

<servlet-name> CXFServlet </ servlet-name>

<url-pattern> / services / * </ url-pattern>

</ Servlet-mapping>

This is only the prelude, the following steps of writing into the service.

2.2 write server-side services and configuration CXF

Service interface file code is as follows:

package com.demo.service.userinfo;

import javax.jws.WebService;

@ WebService / / WebService annotation using jws

/ / If not the label, can not be published as web services, and know not?

public interface IUserService (

public String getPassword (String loginName);

)

Service implementation class file code is as follows

package com.demo.service.userinfo.impl;

import javax.jws.WebService;

import com.demo.service.userinfo.IUserService;

@ WebService / / WebService annotation using jws

/ / If not the label, can not be published as web services, and know not?

public class UserServiceImpl implements IUserService (

@ Override

public String getPassword (String loginName) (

System.out.println ("Server's getPassord () is called:" + loginName);

return loginName + "'s password = 123456";

/ / This is the demo program, so casually written, formal development and the right to remove debugging information

)

)

CXF configuration: configure a file in src applicationContext_cxf.xml, which reads as follows:

<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: soap = "http://cxf.apache.org/bindings/soap"

xsi: schemaLocation = "

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd

http://cxf.apache.org/jaxws

http://cxf.apache.org/schemas/jaxws.xsd ">

<import resource="classpath:META-INF/cxf/cxf.xml" />

<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />

<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<! - This configuration of three lines do not have to check whether the path corresponds to the corresponding file will be automatically generated for cxf ->

<bean/>

<!-UserInfoService do not have to explain that this is a typical Spring configuration, development, suggested by Spring2.5 annotation ->

<Jaxws: endpoint

/ / This should be configured as a client to use to do it, note that I use the web to identify it

implementor = "# userService" / / This is the quote above userService

address = "/ callUserService">

/ / This is the web address of the service call, know why I call the right to use, easy to understand, right?

</ Jaxws: endpoint>

</ Beans>

Note in the above program I write does not increase so much, no time to add the first, second and superfluous, it is proposed ctrl + c and ctrl + v to a certain number of students to pay attention to the matter, do not say my program has problem.

It now has a problem: configured so long, how do not see the wsdl document? No wsdl file, how do you know did the right thing ah? According to the above configuration, visit the URL wsdl how much ah? Guess what?

http://127.0.0.1:8089/webproject/services/callUserService?wsdl

Wsdl the URL can be absurd to access the value of it? (IP address and port number to change based on actual needs its own) If not, you should carefully reflect on friends. Well, we look at the content of our userService the wsdl. See attachment picture.

Server-side steps that done? What do you think about it, right? No, worse last step is to code the client needs into a jar file guide, to return to the client for debugging. Then we complete this final step it.

At the same time with the mouse to select com.demo.service.userinfo and com.demo.service.userinfo, then: Right - "Export .... -" Java -> Jar file - "select save path and file name, save me as "ws.userinfo.jar".

分类:Java 时间:2010-03-26 人气:266
分享到:
blog comments powered by Disqus

相关文章

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.671 (s). 12 q(s)