如何发布一个webservice服务?

时间:2022-03-15 18:23:52
如何发布一个webservice服务?
web.xml里怎么配置,server-config.wsdd是干啥的

10 个解决方案

#1


google 下,起步教程多的是

#2


google过了,我的需求是根据wsdl生成服务端代码并发布到tomcat
我用axis工具,根据wsdl生成了服务端代码和deploy.wsdd。
我配置了web.xml和server-config.xml,不知道是哪块不对,
发布不成功,是不是还缺少什么步骤。

#3


java是发布在tomcat上,c#是发布在IIS上。
你在tomcat发布失败,可能原因有很多,正常情况下,java默认的hello world服务就可以发布,你可能是tomcat与java环境的配置,权限的问题。

#4


(1)webservice写好后部署在tomcat或者其他服务器就等于是发布了
(2)web.xml的配置如下(不过这个文件是建Web Service Project时MyEclipse会自动配置的)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <servlet>
<servlet-name>WebServices</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class>
</servlet>
<servlet>
<servlet-name>SOAPMonitorService</servlet-name>
<servlet-class>
org.apache.axis.monitor.SOAPMonitorService
</servlet-class>
<init-param>
<param-name>SOAPMonitorPort</param-name>
<param-value>5001</param-value>
</init-param>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AdminServlet
</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>SOAPMonitorService</servlet-name>
<url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>WebServices</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>WebServices</servlet-name>
<url-pattern>/WebServices/*</url-pattern>
</servlet-mapping>
  <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


(3)server-config.wsdd是配置服务用的,也就是配置你写的Web Service,我放个例子供你参考
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="adminPassword" value="admin" />
<parameter name="enableNamespacePrefixOptimization"
value="true" />
<parameter name="dotNetSoapEncFix" value="true" />
<parameter name="disablePrettyXML" value="true" />
<parameter name="sendXsiTypes" value="true" />
<parameter name="sendMultiRefs" value="true" />
<parameter name="sendXMLDeclaration" value="true" />
<requestFlow name="RequestFlow1">
<handler name="Handler1"
type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="session" />
</handler>
<handler name="Handler2"
type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="request" />
<parameter name="extension" value=".jwr" />
</handler>
</requestFlow>
</globalConfiguration>
<responseFlow name="ResponseFlow1">
<handler name="Handler1" type="LocalResponder" />
</responseFlow>
<handler name="Handler1" type="LocalResponder" />
<handler name="LocalResponder"
type="java:org.apache.axis.transport.local.LocalResponder" />
<handler name="URLMapper"
type="java:org.apache.axis.handlers.http.URLMapper" />
<handler name="Authenticate"
type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
<handler name="Handler2"
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
<requestFlow name="RequestFlow1">
<handler name="Handler1" type="URLMapper" />
<handler name="Handler2"
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
</requestFlow>
<service name="AdminService" provider="java:MSG">
<parameter name="allowedMethods" value="AdminService" />
<parameter name="enableRemoteAdmin" value="false" />
<parameter name="className" value="org.apache.axis.utils.Admin" />
<namespace>http://xml.apache.org/axis/wsdd/</namespace>
</service>
<service name="Version" provider="java:RPC">
<parameter name="allowedMethods" value="getVersion" />
<parameter name="className" value="org.apache.axis.Version" />
</service>

<!-- 开放一个服务 -->
<service name="gsNotify" provider="java:RPC">
<parameter name="allowedMethods" value="*" />
<parameter name="className"
value="web.GsNotifyImp" />
<parameter name="scope" value="Request" />
<namespace>nss</namespace>         
</service>

<transport name="http">
<requestFlow name="RequestFlow1">
<handler name="Handler1" type="URLMapper" />
<handler name="Handler2"
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
</requestFlow>
<parameter name="qs:list"
value="org.apache.axis.transport.http.QSListHandler" />
<parameter name="qs:wsdl"
value="org.apache.axis.transport.http.QSWSDLHandler" />
<parameter name="qs:method"
value="org.apache.axis.transport.http.QSMethodHandler" />
</transport>
<transport name="local">
<responseFlow name="ResponseFlow1">
<handler name="Handler1" type="LocalResponder" />
</responseFlow>
</transport>
</deployment>

#5


谢谢回复!
我用axis生成server-config.wsdd老报错,解决不了,
java org.apache.axis.client.AdminClient -l

#6


用wsdl生成服务器端代码后,会生成一个deploy.wsdd,使用ant或命令行来部署服务:
1. 使用ant部署服务
build.xml内容如下:
<project name="SimpleService">
<property name="axis.home" value="C:\axis1.4" />
<path id="axis.classpath">
<fileset dir="${axis.home}/lib">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef resource="axis-tasks.properties"
classpathref="axis.classpath" />
<target name="generate-service-stub" >
<axis-wsdl2java serverside="true" url="./wsdl/WsClient.wsdl" output="../server-code">
<!-- <mapping namespace="http://www.example.org/SimpleService/"
package="com.cvicse.middleware" /> -->
</axis-wsdl2java>
</target>
<target name="deploy">
<axis-admin url="http://localhost:5080/Axis-Wrapped-Server2/servlet/AxisServlet"
xmlfile="./WEB-INF/deploy.wsdd" />
</target>
<target name="generate-client-stub">
<axis-wsdl2java url="./wsdl/WsClient.wsdl" output="../client-code">
</axis-wsdl2java>
</target>

<target name="undeploy">
<axis-admin url="http://localhost:5080/Axis-Wrapped-Server2/servlet/AxisServlet"
xmlfile="./undeploy.wsdd" />
</target>
</project>
首先机器要有一个ant的版本,如果使用eclipse的话就不用了,自带了ant,然后在合适的路径下运行命令行: ant deploy

2. 用命令行
java org.apache.axis.client.AdminClient  http://localhost:8080/servicename/  deploy.wsdd

#7


我用命令行java org.apache.axis.client.AdminClient  http://localhost:8080/servicename/  deploy.wsdd 
老是报错,愁死我了,这是什么问题啊
Exception: AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode:
 faultString: org.xml.sax.SAXNotRecognizedException: Feature: http://xml.org/sax
/properties/lexical-handler
 faultActor:
 faultNode:
 faultDetail:
        {http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXNotRecognizedExce
ption: Feature: http://xml.org/sax/properties/lexical-handler
        at org.apache.xerces.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:1
55)
        at org.apache.axis.encoding.DeserializationContext.parse(Deserialization
Context.java:226)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
        at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnders
tandChecker.java:62)
        at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
        at org.apache.axis.client.Call.invoke(Call.java:2767)
        at org.apache.axis.client.Call.invoke(Call.java:1792)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:439)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:404)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:410)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:320)
        at org.apache.axis.client.AdminClient.main(AdminClient.java:463)

        {http://xml.apache.org/axis/}hostname:2B24E976FF2B47D

#8


如果用ant的话,这个build.xml是自己写吗?

#9


搞了2天,问题都解决了,哎 不容易啊,抽空把webservice的东西整理下
谢谢大家的回复

#10


该回复于2015-05-26 09:54:47被管理员删除

#1


google 下,起步教程多的是

#2


google过了,我的需求是根据wsdl生成服务端代码并发布到tomcat
我用axis工具,根据wsdl生成了服务端代码和deploy.wsdd。
我配置了web.xml和server-config.xml,不知道是哪块不对,
发布不成功,是不是还缺少什么步骤。

#3


java是发布在tomcat上,c#是发布在IIS上。
你在tomcat发布失败,可能原因有很多,正常情况下,java默认的hello world服务就可以发布,你可能是tomcat与java环境的配置,权限的问题。

#4


(1)webservice写好后部署在tomcat或者其他服务器就等于是发布了
(2)web.xml的配置如下(不过这个文件是建Web Service Project时MyEclipse会自动配置的)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <servlet>
<servlet-name>WebServices</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class>
</servlet>
<servlet>
<servlet-name>SOAPMonitorService</servlet-name>
<servlet-class>
org.apache.axis.monitor.SOAPMonitorService
</servlet-class>
<init-param>
<param-name>SOAPMonitorPort</param-name>
<param-value>5001</param-value>
</init-param>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AdminServlet
</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>SOAPMonitorService</servlet-name>
<url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>WebServices</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>WebServices</servlet-name>
<url-pattern>/WebServices/*</url-pattern>
</servlet-mapping>
  <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


(3)server-config.wsdd是配置服务用的,也就是配置你写的Web Service,我放个例子供你参考
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="adminPassword" value="admin" />
<parameter name="enableNamespacePrefixOptimization"
value="true" />
<parameter name="dotNetSoapEncFix" value="true" />
<parameter name="disablePrettyXML" value="true" />
<parameter name="sendXsiTypes" value="true" />
<parameter name="sendMultiRefs" value="true" />
<parameter name="sendXMLDeclaration" value="true" />
<requestFlow name="RequestFlow1">
<handler name="Handler1"
type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="session" />
</handler>
<handler name="Handler2"
type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="request" />
<parameter name="extension" value=".jwr" />
</handler>
</requestFlow>
</globalConfiguration>
<responseFlow name="ResponseFlow1">
<handler name="Handler1" type="LocalResponder" />
</responseFlow>
<handler name="Handler1" type="LocalResponder" />
<handler name="LocalResponder"
type="java:org.apache.axis.transport.local.LocalResponder" />
<handler name="URLMapper"
type="java:org.apache.axis.handlers.http.URLMapper" />
<handler name="Authenticate"
type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
<handler name="Handler2"
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
<requestFlow name="RequestFlow1">
<handler name="Handler1" type="URLMapper" />
<handler name="Handler2"
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
</requestFlow>
<service name="AdminService" provider="java:MSG">
<parameter name="allowedMethods" value="AdminService" />
<parameter name="enableRemoteAdmin" value="false" />
<parameter name="className" value="org.apache.axis.utils.Admin" />
<namespace>http://xml.apache.org/axis/wsdd/</namespace>
</service>
<service name="Version" provider="java:RPC">
<parameter name="allowedMethods" value="getVersion" />
<parameter name="className" value="org.apache.axis.Version" />
</service>

<!-- 开放一个服务 -->
<service name="gsNotify" provider="java:RPC">
<parameter name="allowedMethods" value="*" />
<parameter name="className"
value="web.GsNotifyImp" />
<parameter name="scope" value="Request" />
<namespace>nss</namespace>         
</service>

<transport name="http">
<requestFlow name="RequestFlow1">
<handler name="Handler1" type="URLMapper" />
<handler name="Handler2"
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
</requestFlow>
<parameter name="qs:list"
value="org.apache.axis.transport.http.QSListHandler" />
<parameter name="qs:wsdl"
value="org.apache.axis.transport.http.QSWSDLHandler" />
<parameter name="qs:method"
value="org.apache.axis.transport.http.QSMethodHandler" />
</transport>
<transport name="local">
<responseFlow name="ResponseFlow1">
<handler name="Handler1" type="LocalResponder" />
</responseFlow>
</transport>
</deployment>

#5


谢谢回复!
我用axis生成server-config.wsdd老报错,解决不了,
java org.apache.axis.client.AdminClient -l

#6


用wsdl生成服务器端代码后,会生成一个deploy.wsdd,使用ant或命令行来部署服务:
1. 使用ant部署服务
build.xml内容如下:
<project name="SimpleService">
<property name="axis.home" value="C:\axis1.4" />
<path id="axis.classpath">
<fileset dir="${axis.home}/lib">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef resource="axis-tasks.properties"
classpathref="axis.classpath" />
<target name="generate-service-stub" >
<axis-wsdl2java serverside="true" url="./wsdl/WsClient.wsdl" output="../server-code">
<!-- <mapping namespace="http://www.example.org/SimpleService/"
package="com.cvicse.middleware" /> -->
</axis-wsdl2java>
</target>
<target name="deploy">
<axis-admin url="http://localhost:5080/Axis-Wrapped-Server2/servlet/AxisServlet"
xmlfile="./WEB-INF/deploy.wsdd" />
</target>
<target name="generate-client-stub">
<axis-wsdl2java url="./wsdl/WsClient.wsdl" output="../client-code">
</axis-wsdl2java>
</target>

<target name="undeploy">
<axis-admin url="http://localhost:5080/Axis-Wrapped-Server2/servlet/AxisServlet"
xmlfile="./undeploy.wsdd" />
</target>
</project>
首先机器要有一个ant的版本,如果使用eclipse的话就不用了,自带了ant,然后在合适的路径下运行命令行: ant deploy

2. 用命令行
java org.apache.axis.client.AdminClient  http://localhost:8080/servicename/  deploy.wsdd

#7


我用命令行java org.apache.axis.client.AdminClient  http://localhost:8080/servicename/  deploy.wsdd 
老是报错,愁死我了,这是什么问题啊
Exception: AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode:
 faultString: org.xml.sax.SAXNotRecognizedException: Feature: http://xml.org/sax
/properties/lexical-handler
 faultActor:
 faultNode:
 faultDetail:
        {http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXNotRecognizedExce
ption: Feature: http://xml.org/sax/properties/lexical-handler
        at org.apache.xerces.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:1
55)
        at org.apache.axis.encoding.DeserializationContext.parse(Deserialization
Context.java:226)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
        at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnders
tandChecker.java:62)
        at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
        at org.apache.axis.client.Call.invoke(Call.java:2767)
        at org.apache.axis.client.Call.invoke(Call.java:1792)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:439)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:404)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:410)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:320)
        at org.apache.axis.client.AdminClient.main(AdminClient.java:463)

        {http://xml.apache.org/axis/}hostname:2B24E976FF2B47D

#8


如果用ant的话,这个build.xml是自己写吗?

#9


搞了2天,问题都解决了,哎 不容易啊,抽空把webservice的东西整理下
谢谢大家的回复

#10


该回复于2015-05-26 09:54:47被管理员删除