大家好,
我用delphi写了一个webservice,用delphi作为客户端调用测试已经没问题。现在需要用extjs调用webservice里的函数,我该如何做?
1. 用其它语言调用webservice时,都要用wsdl地址(如:
http://localhost:8080/wsdl/IMyWebService)保存一个webservice的所有函数的定义等的文件,用extjs是否也需要?如果需要如何做?
2. 我的代码如下,不行,操作时服务器端调用的函数根本就没有进入,说明方法不对。
<html>
<head>
<title>ExtJs测试</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
<script type="text/javascript" src="ext-all.js"></script>
<script type="text/javascript" src="adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-lang-zh_CN.js"></script>
<script language="javascript">
Ext.onReady(function(){
var soap = "";
soap += '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:MyWebServiceIntf-IMyWebService">';
soap += '<soapenv:Header/>';
soap += '<soapenv:Body>';
soap += '<urn:echoTest soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">';
soap += ' <ms_true xsi:type="xsd:string">123456</ms_true>';
soap += '</urn:echoTest>';
soap += ' </soapenv:Body>';
soap += '</soapenv:Envelope>';
Ext.Ajax.request({
url:"http://localhost:8080/IMyWebService",
data: soap,
method:"post",
contentType: "text/xml;charset=UTF-8",
success:function(response,options){
Ext.Msg.alert('成功',response.responseText);
},
failure:function(){
Ext.Msg.alert('失败','与Webservice连接失败');
}
});
});
</script>
</head>
<body>
</body>
</html>
我用jquery测试的代码如下:
<!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>
<title>test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready( function(){
var soap = "";
soap += '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:MyWebServiceIntf-IMyWebService">';
soap += '<soapenv:Header/>';
soap += '<soapenv:Body>';
soap += '<urn:echoTest soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">';
soap += ' <ms_true xsi:type="xsd:string">123456</ms_true>';
soap += '</urn:echoTest>';
soap += ' </soapenv:Body>';
soap += '</soapenv:Envelope>';
$.ajax({
url:"http://localhost:8080/soap/IMyWebService",
contentType: "text/xml;charset=UTF-8",
data: soap,
method:"post",
success:function(response,options){
Ext.Msg.alert('成功',response.responseText);
},
failure:function(){
Ext.Msg.alert('失败','与Webservice连接失败');
}
});
});
</script>
</head>
<body>
</body>
</html>
请大家帮忙看一下,有什么方法?
我总感觉我上面的代码的书写有问题,但不知是哪里,比如:url, data,soap 等
我的soap值是用soapUI工具测试后复制的,然后把它的?改成12345值而已.是否url值有问题?
在soapUI中的raw页中中值是:
POST http://localhost:8080/soap/IMyWebService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:MyWebServiceIntf-IMyWebService#echoTest"
Content-Length: 468
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
先谢谢大家!!!!!!!
附:
http://localhost:8080/wsdl/IMyWebService的内容如下:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" name="IZCWebServiceservice" targetNamespace="http://tempuri.org/">
<message name="echoTest0Request">
<part name="ms_true" type="xs:string"/>
</message>
<message name="echoTest0Response">
<part name="return" type="xs:string"/>
</message>
<message name="login1Request">
<part name="ms_option" type="xs:string"/>
</message>
<message name="login1Response">
<part name="return" type="xs:string"/>
</message>
<message name="logout2Request">
<part name="ms_option" type="xs:string"/>
</message>
<message name="logout2Response">
<part name="return" type="xs:string"/>
</message>
<message name="querySQL3Request">
<part name="ms_option" type="xs:string"/>
</message>
<message name="querySQL3Response">
<part name="return" type="xs:string"/>
</message>
<message name="execSQL4Request">
<part name="ms_option" type="xs:string"/>
</message>
<message name="execSQL4Response">
<part name="return" type="xs:string"/>
</message>
<message name="getFileList5Request">
<part name="ms_rand" type="xs:string"/>
</message>
<message name="getFileList5Response">
<part name="return" type="xs:string"/>
</message>
<message name="getFile6Request">
<part name="ms_rand" type="xs:string"/>
<part name="ms_fileName" type="xs:string"/>
</message>
<message name="getFile6Response">
<part name="return" type="xs:base64Binary"/>
</message>
<portType name="IMyWebService">
<operation name="echoTest">
<input message="tns:echoTest0Request"/>
<output message="tns:echoTest0Response"/>
</operation>
<operation name="login">
<input message="tns:login1Request"/>
<output message="tns:login1Response"/>
</operation>
<operation name="logout">
<input message="tns:logout2Request"/>
<output message="tns:logout2Response"/>
</operation>
<operation name="querySQL">
<input message="tns:querySQL3Request"/>
<output message="tns:querySQL3Response"/>
</operation>
<operation name="execSQL">
<input message="tns:execSQL4Request"/>
<output message="tns:execSQL4Response"/>
</operation>
<operation name="getFileList">
<input message="tns:getFileList5Request"/>
<output message="tns:getFileList5Response"/>
</operation>
<operation name="getFile">
<input message="tns:getFile6Request"/>
<output message="tns:getFile6Response"/>
</operation>
</portType>
<binding name="IMyWebServicebinding" type="tns:IMyWebService">
<binding xmlns="http://schemas.xmlsoap.org/wsdl/soap/" style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="echoTest">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:MyWebServiceIntf-IMyWebService#echoTest" style="rpc"/>
<input>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</input>
<output>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</output>
</operation>
<operation name="login">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:MyWebServiceIntf-IMyWebService#login" style="rpc"/>
<input>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</input>
<output>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</output>
</operation>
<operation name="logout">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:MyWebServiceIntf-IMyWebService#logout" style="rpc"/>
<input>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</input>
<output>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</output>
</operation>
<operation name="querySQL">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:MyWebServiceIntf-IMyWebService#querySQL" style="rpc"/>
<input>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</input>
<output>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</output>
</operation>
<operation name="execSQL">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:MyWebServiceIntf-IMyWebService#execSQL" style="rpc"/>
<input>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</input>
<output>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</output>
</operation>
<operation name="getFileList">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:MyWebServiceIntf-IMyWebService#getFileList" style="rpc"/>
<input>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</input>
<output>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</output>
</operation>
<operation name="getFile">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:MyWebServiceIntf-IMyWebService#getFile" style="rpc"/>
<input>
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</input>
<output>
<mime:multipartRelated>
<part xmlns="http://schemas.xmlsoap.org/wsdl/mime/">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:MyWebServiceIntf-IMyWebService"/>
</part>
<part xmlns="http://schemas.xmlsoap.org/wsdl/mime/">
<content part="return" type="application/binary"/>
</part>
</mime:multipartRelated>
</output>
</operation>
</binding>
<service name="IMyWebServiceservice">
<port name="IMyWebServicePort" binding="tns:IMyWebServicebinding">
<address xmlns="http://schemas.xmlsoap.org/wsdl/soap/" location="http://localhost:8080/soap/IMyWebService"/>
</port>
</service>
</definitions>
webservice的style有两种,即rpc和document。delphi写的这个的style为rpc,看一下上面的代码就知道了,这个有什么代码需要写吗?
谢谢大家!!!
...
※ 修改:·darlingpeng 于 Jul 12 11:42:03 2016 修改本文·[FROM: 59.49.77.*]
※ 来源:·水木社区
http://www.newsmth.net·[FROM: 59.49.77.*]
修改:darlingpeng FROM 59.49.77.*
FROM 59.49.77.*