java实现webservice实例
∙ java功能
JavaWebServiceApacheServletXML
研究下WEBSERVICE,从网上了好多实例,但很多写的让人实在难以恭维,花了三个小时的圈圈转后总算搞通了,其实也挺简单的,这里特别感谢www.liuzm/article/java/992.htm
一:
首先创建个WEB工程,然后: /axis/网站下载Axis安装包.当然还依赖其他包的,我这里在附件里上传了所有应用到得包,方便大家。
二:
然后就写wsdd 文件(注:其实这里真的不用,可以跳过第二步)为了生成这个文件:server-config.wsdd
deploy.wsdd:
<deployment xmlns="/axis/wsdd/" xmlns:java="" target="_blank">/axis/wsdd/providers/java">
<service name="HelloWorld" provider="java:RPC">
<parameter name="className" value="HelloWorld"/>
<parameter name="allowedMethods" value="sayHello"/>
</service>
</deployment>
<service name="HelloWorld" provider="java:RPC">
<parameter name="className" value="HelloWorld"/>
<parameter name="allowedMethods" value="sayHello"/>
</service>
</deployment>
在DOS下转换目录到%TOMCAT_HOME%\webapps\axis\WEB-INF,命令:
java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient deploy.wsdd
java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient deploy.wsdd
三:
可以自己写第二步中的文件,代码如下:
Wsdd代码
1. <?xml version="1.0" encoding="UTF-8"?>
2. <deployment xmlns="/axis/wsdd/" xmlns:java="/axis/wsdd/providers/java">
3.
4. <globalConfiguration>
5. <parameter name="sendMultiRefs" value="true"/>
6. <parameter name="disablePrettyXML" value="true"/>
7. <parameter name="dotNetSoapEncFix" value="true"/>
8. <parameter name="enableNamespacePrefixOptimization" value="false"/>
9. <parameter name="sendXMLDeclaration" value="true"/>
10. <parameter name="sendXsiTypes" value="true"/>
11. <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
12. </globalConfiguration>
13.
14. <handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/>
15. <service name="Login.jws" provider="java:RPC">
16. <parameter name="className" value="server.SayHello"/>
17. <parameter name="scope" value="request"/>
18. <parameter name="allowedMethods" value="*"/>
19. <messageReceiver class="org.ivers.RawXMLINOutMessageReceiver"/>
20. </service>
21. <transport name="http">
22. <requestFlow>
23. <handler type="URLMapper"/>
24. </requestFlow>
25. </transport>
26. </deployment>
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="/axis/wsdd/" xmlns:java="/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="sendMultiRefs" value="true"/>
<parameter name="disablePrettyXML" value="true"/>
<parameter name="dotNetSoapEncFix" value="true"/>
<parameter name="enableNamespacePrefixOptimization" value="false"/>
<parameter name="sendXMLDeclaration" value="true"/>
<parameter name="sendXsiTypes" value="true"/>
<parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
</globalConfiguration>
<handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/>
<service name="Login.jws" provider="java:RPC">
<parameter name="className" value="server.SayHello"/>
<parameter name="scope" value="request"/>
<parameter name="allowedMethods" value="*"/>
<messageReceiver class="org.ivers.RawXMLINOutMessageReceiver"/>
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper"/>
</requestFlow>
</transport>
</deployment>
放到 WEB-INF 目录下 和l一起,其中,WEB.XML可以直接从你下载的axis项目中拿来到自己工程就好,或者自己添加:
Xml代码
1. <servlet>
2. <servlet-name>AxisServlet</servlet-name>
3. <servlet-class>org.ansport.http.AxisServlet</servlet-class>
4. </servlet>
5. <servlet-mapping>
6. <servlet-name>AxisServlet</servlet-name>
7. <url-pattern>/services/*</url-pattern>
8. </servlet-mapping>
<servlet>
<servlet-name>AxisServlet</servlet-name>
调用webservice服务 <servlet-class>org.ansport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
四:
服务端提供的方法:
Java代码
1. package server;
2.
3. public class SayHello {
4. public String getName(String name) {
5. return "hello====>" + name;
6. }
7. }
package server;
public class SayHello {
public String getName(String name) {
return "hello====>" + name;
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论