您的位置:首页 > 编程语言 > Java开发

.net 调用java WebService简单教程

2011-05-23 16:06 603 查看

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: