JBOSS下Web 服务(Web Service)开发步骤

<script type="text/javascript"> document.body.oncopy = function() { if (window.clipboardData) { setTimeout(function() { var text = clipboardData.getData("text"); if (text && text.length>300) { text = text + "/r/n/n本文来自CSDN博客,转载请标明出处:" + location.href; clipboardData.setData("text", text); } }, 100); } } </script> <script class="blogstory">function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>

. 开发一个 JSR-181 POJO Endpoint Web Service 应遵守下面几个步骤:

1> 建立一个 POJO endpoint

import javax.jws.WebMethod;

import javax.jws.WebService;

import javax.jws.soap.SOAPBinding;

 

@WebService(name = "HelloWorld", targetNamespace = "http://webservice", serviceName = "HelloWorldService")

//targetNamespace , 与包名相同

@SOAPBinding(style = SOAPBinding.Style.RPC)

public class HelloWorldService {

         @WebMethod

         public String SayHello(String name) {

                   return name + " : 这是我的第一个 web 服务 ";

         }

}

 

可能有错误,则加入: jboss-jaxws.jar 

@WebService 这个注释放置在 Java 类的前面,声明这个类的部分方法可以被发布为 Web 服务。

@WebService 的属性用于设置 Web 服务被发布时的一些配置信息,常用的属性说明如下

1. name

Web 服务的名字, WSDL wsdl:portType 元素的 name 属性和它保持一致,默认是 Java 类或者接口的名字。

2. serviceName

Web 服务的服务名, WSDL wsdl:service 元素的 name 属性和它保持一致,默认是 Java 类的名字 + Service ” 。

3. targetNamespace

WSDL 文件所使用的 namespace ,该 Web 服务中所产生的其他 XML 文档同样采用这个作为 namespace

@SOAPBinding() 表示这个服务可以映射到一个 SOAP 消息中。 Style 用于指定 SOAP 消息请求和回应的编码方式。

@WebMethod 这个注释放在需要被发布成 Web 服务的方法前面。

 

2> endpoint 定义成一个 servlet

<?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">

<servlet>

<servlet-name>HelloWorldService</servlet-name>

<servlet-class>webservice.HelloWorldService</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>HelloWorldService</servlet-name>

<url-pattern>/HelloWorldService/*</url-pattern>

</servlet-mapping>

</web-app>

3> endpoint 打包成一个 Web 应用 (war 文件 )

进入所在目录:打成 war :   jar  cvf   TestWS.war  * 

 

4> 测试

输入: http://localhost:8080/jbossws/ 进入 JbossWS 的查看界面

 

.web service 客户端调用

我们采用 Xfire 进行 webservice 客户端调用 详见: http://blog.csdn.net/pengchua/archive/2007/08/02/1722156.aspx

 

三.问题解决:

1. 问题

2008-7-25 8:56:37 org.apache.axis.utils.JavaUtils isAttachmentSupported

警告 : Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.

AxisFault

  faultCode: { http://schemas.xmlsoap.org/soap/envelope/}Server.userException

  faultSubcode:

  faultString: org.xml.sax.SAXParseException : Premature end of file.

  faultActor:

  faultNode:

  faultDetail:

    { http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXParseException : Premature end of file.

    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)

解决:放入 activation.jar mail.jar

2 问题: : jboss 控制台上出现错误 Caused by: java.lang.UnsupportedOperationException: setProperty must be overridden by all subclasses of SOAPMessage
| at javax.xml.soap.SOAPMessage.setProperty(SOAPMessage.java:424)
解决: This usually shows up when running with JDK 6. If that is the case, either use JDK 5, 也就是将 %JAVA_HOME% 变成 jdk1.5. or see http://wiki.jboss.org/wiki/JBossWithJDK6?action=e&windowstate=normal&mode=view

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值