下面是 webService+Flex 项目的主要代码!
附件内容: webservice 简单项目, flex 项目, webService+Flex 项目说明文档( .DOC ), flex webService 经典例子(翻译) TXT 文档
因为用两个项目文件可能会比较大有18MB多所以我把webService里的JAR包给删了!现在只有5MB多
附件里面是完整的 webService , flex 项目!还有对这个个项目的一些说明( word 文档)
我想加了这些东西,你只要学过 JAVA ( J2EE )没学过 webService 的都能看懂!不过还得有点 FLEX 的基础!如果不会 FLEX 可以看我的另一遍 BLOG :《 myEclipse+Flex》
Flex 项目 (test)
主要代码
Webservices.mxml 代码如下:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:WebService id="ws" wsdl="http://localhost:8080/webService/services/CompanyService?wsdl" useProxy="false" showBusyCursor="true"> <mx:operation name="putCompany" result="Alert.show('恭喜!添加成功','返回框',3)" fault="Alert.show('添加失败','失败',3)"> </mx:operation> <mx:operation name="getCompanyCEO" result="showInfo(event)" fault="Alert.show('失败','tile',2)"> </mx:operation> </mx:WebService> <mx:XML> </mx:XML> <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.controls.Alert; private var com:String ; private var cio:String ; public function addCompany():void { com = company.text ; cio = ceo.text ; ws.putCompany(com,cio); } public function seeCeo():void { var str:String; str = company.text; ws.getCompanyCEO(str); } public function showInfo(event:ResultEvent):void { var str:String; str = event.result.toString(); Alert.show(str,"凯旋",2); } ]]> </mx:Script> <mx:Panel title="DataGrid Control Example" height="100%" width="100%" paddingTop="10" paddingLeft="10" paddingRight="10"> <mx:Label x="10" y="10" text="公司" height="39" width="55" fontSize="21" fontWeight="bold"/> <mx:TextInput x="61" y="10" height="31" id="company" fontSize="20"/> <mx:Label x="10" y="66" text="老大" width="55" height="49" fontSize="21" fontWeight="bold"/> <mx:TextInput x="61" y="75" height="31" id="ceo" fontSize="20"/> <mx:Button label="添加" height="37" fontSize="17" id="add" click="addCompany();"/> <mx:Button label="查看(输入公司查老大)" height="29" fontSize="17" id="see" click="seeCeo();"/> </mx:Panel> </mx:Application>
webService 项目 (webService)
主要代码
Web.xml
<?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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>
org.codehaus.xfire.transport.http.XFireConfigurableServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/servlet/XFireServlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
CompanyServiceImpl 代码( java )
package entity;
import java.util.HashMap;
public class CompanyServiceImpl{
HashMap<String,String> m=new HashMap<String,String>();
public void into(){
m.put("虚虚公司", "虚虚象");
m.put("微软", "zwh");
}
public String getCompanyCEO(String company) {
into();
return m.get(company);
}
public void putCompany(String company,String CEO){
m.put(company, CEO);
}
}
Services.xml
详细路径: webService/src/META-INF/xfire/services.xml
注意: META-INF 是自己在 SRC 下建的一个文件夹,并不是 WebRoot 里面的 META-INF
<beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>CompanyService</name> <namespace>http://xfire.codehaus.org/CompanyService</namespace> <serviceClass>entity.CompanyServiceImpl</serviceClass> <!-- <serviceClass>entity.CompanyService</serviceClass> <implementationClass>entity.CompanyServiceImpl</implementationClass> --> </service> </beans>
http://localhost:8080/webService/services/CompanyService?wsdl
<?xml version="1.0" encoding="UTF-8" ?> - <wsdl:definitions targetNamespace="http://xfire.codehaus.org/CompanyService" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:tns="http://xfire.codehaus.org/CompanyService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> - <wsdl:types> - <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://xfire.codehaus.org/CompanyService"> - <xsd:element name="getCompany"> <xsd:complexType /> </xsd:element> - <xsd:element name="getCompanyResponse"> - <xsd:complexType> - <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types> - <wsdl:message name="getCompanyRequest"> <wsdl:part name="parameters" element="tns:getCompany" /> </wsdl:message> + <wsdl:message name="getCompanyResponse"> <wsdl:part name="parameters" element="tns:getCompanyResponse" /> </wsdl:message> - <wsdl:portType name="CompanyServicePortType"> - <wsdl:operation name="getCompany"> <wsdl:input name="getCompanyRequest" message="tns:getCompanyRequest" /> <wsdl:output name="getCompanyResponse" message="tns:getCompanyResponse" /> </wsdl:operation> </wsdl:portType> - <wsdl:binding name="CompanyServiceHttpBinding" type="tns:CompanyServicePortType"> <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> - <wsdl:operation name="getCompany"> <wsdlsoap:operation soapAction="" /> - <wsdl:input name="getCompanyRequest"> <wsdlsoap:body use="literal" /> </wsdl:input> - <wsdl:output name="getCompanyResponse"> <wsdlsoap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> - <wsdl:service name="CompanyService"> - <wsdl:port name="CompanyServiceHttpPort" binding="tns:CompanyServiceHttpBinding"> <wsdlsoap:address location="http://localhost:8080/webService/services/CompanyService" /> </wsdl:port> </wsdl:service> </wsdl:definitions>