java 滴WebService配置比較複雜
tomcat + jdk + cxf + spring +(strtus)看你心情吧 = =
首先·建立一個··WebProject
把cxf裡面的lib再再裡面的庫複製到你的工程下···我java菜吖··不知道哪些必須滴···懶人全都放進去額
接著開始寫代碼啦··
package com.ws; import javax.jws.WebService; @WebService public interface IHello { public String HelloWord(); } package com.ws; import javax.jws.WebService; @WebService public class Hello implements IHello{ public String HelloWord() { // TODO Auto-generated method stub return "hello 5+x"; } }
配置spring
<?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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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" /> <jaxws:endpoint id="hello" implementor="com.ws.Hello" address="/Hello" /> </beans>
配置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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> <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/beans.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
好了··啟動tomcat吧·
·WebService 搭建成功咯···
下面就試試用.net 調用它
建立.net網站
首頁 布置一個label 和 button
<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>無標題頁</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> </div> </form> </body> </html>
.net 的WebService就簡單多了····右鍵工程···添加Web引用
雙擊button進入點擊事件代碼編輯
protected void Button1_Click(object sender, EventArgs e) { WS.HelloService _ws = new WS.HelloService(); Label1.Text = _ws.HelloWord(); }
啟動.net 網站
哈,,,就是這樣咯。。
還是逃離不鳥java滴魔掌,,剛研究鳥一下,就寫下來備忘。
java滴開發環境··查錯很難吖,,不知道是不是我滴水平問題額···哈哈哈哈哈哈哈
name:5+x