JSP 如何调用 web Service?

fancuixia 2004-10-10 07:43:39
WSDL文件如下:
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="http://localhost:7001/webApp/services/ws" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:7001/webApp/services/ws" xmlns:intf="http://localhost:7001/webApp/services/ws" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <wsdl:message name="addResponse">
<wsdl:part name="addReturn" type="xsd:int" />
</wsdl:message>
<wsdl:message name="getNameRequest" />
- <wsdl:message name="addRequest">
<wsdl:part name="a" type="xsd:int" />
<wsdl:part name="b" type="xsd:int" />
</wsdl:message>
- <wsdl:message name="getNameResponse">
<wsdl:part name="getNameReturn" type="xsd:string" />
</wsdl:message>
- <wsdl:portType name="ws">
- <wsdl:operation name="getName">
<wsdl:input message="impl:getNameRequest" name="getNameRequest" />
<wsdl:output message="impl:getNameResponse" name="getNameResponse" />
</wsdl:operation>
- <wsdl:operation name="add" parameterOrder="a b">
<wsdl:input message="impl:addRequest" name="addRequest" />
<wsdl:output message="impl:addResponse" name="addResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="wsSoapBinding" type="impl:ws">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="getName">
<wsdlsoap:operation soapAction="" />
- <wsdl:input name="getNameRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:7001/webApp/services/ws" use="encoded" />
</wsdl:input>
- <wsdl:output name="getNameResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:7001/webApp/services/ws" use="encoded" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="add">
<wsdlsoap:operation soapAction="" />
- <wsdl:input name="addRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:7001/webApp/services/ws" use="encoded" />
</wsdl:input>
- <wsdl:output name="addResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:7001/webApp/services/ws" use="encoded" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="wsService">
- <wsdl:port binding="impl:wsSoapBinding" name="ws">
<wsdlsoap:address location="http://localhost:7001/webApp/services/ws" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

一个方法是getName, 不带参数;一个是add,带两个参数。

我想通过客户端脚本也能访问,就是不知道怎么写。
如果能够在jsp中调用,也可以。
谢谢
...全文
138 8 打赏 收藏 举报
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
legumer 2005-05-13
顶下
有人知道吗?
  • 打赏
  • 举报
回复
legumer 2005-05-13
顶下
有任知道吗?
  • 打赏
  • 举报
回复
以梦为马 2005-02-04
up
  • 打赏
  • 举报
回复
maweihua 2005-02-04
不明白,up
  • 打赏
  • 举报
回复
iwdc 2004-10-11
友情up
  • 打赏
  • 举报
回复
fancuixia 2004-10-10
web service 是在JBuilder 9中 export one class as web service 生成的。
  • 打赏
  • 举报
回复
fancuixia 2004-10-10
用一下脚本访问,提示NoService

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="vbscript">
Dim url,xmlhttp,dom,node,xmlDOC
'根据webservice的测试页不同的方法构造不同的soap request
SoapRequest = "<?xml version="&CHR(34)&"1.0"&CHR(34)&" encoding="&CHR(34)&"utf-8"&CHR(34)&"?>"& _
"<soap:Envelope xmlns:xsi="&CHR(34)&"http://www.w3.org/2001/XMLSchema-instance"&CHR(34)&" "& _
"xmlns:xsd="&CHR(34)&"http://www.w3.org/2001/XMLSchema"&CHR(34)&" "& _
"xmlns:soap="&CHR(34)&"http://schemas.xmlsoap.org/soap/envelope/"&CHR(34)&">"& _
"<soap:Body>"& _
"<add xmlns="&CHR(34)&"http://localhost"&CHR(34)&">"& _
"<x>3</x>"& _
"<y>4</y>"& _
"</add>"& _
"</soap:Body>"& _
"</soap:Envelope>"
'url = "http://www.xxxx.com/Service1.asmx?methodname=Add"
url = "http://localhost:7001/webApp/services/ws/add"
Set xmlDOC =CreateObject("MSXML.DOMDocument")
xmlDOC.loadXML(SoapRequest)
Set xmlhttp = CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "text/xml;charset=utf-8"
'SOAPAction这个Header头同样可以在sample中找到
xmlhttp.setRequestHeader "SOAPAction", "http://localhost:7001/webApp/services/ws"
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.Send(xmlDOC)
msgbox xmlhttp.Status
msgbox xmlhttp.StatusText
msgbox xmlhttp.responseText
If xmlhttp.Status = 200 Then
xmlDOC.load(xmlhttp.responseXML)
msgbox "执行结果为:"&xmlDOC.getElementsByTagName("addResult")(0).text
else
msgbox "failed"
end if
</script>

</HEAD>

<BODY>

</BODY>
</HTML>
  • 打赏
  • 举报
回复
fancuixia 2004-10-10
在线等待
  • 打赏
  • 举报
回复
发帖
Web 开发

8.0w+

社区成员

Java Web 开发
社区管理员
  • Web 开发社区
加入社区
帖子事件
创建了帖子
2004-10-10 07:43
社区公告
暂无公告