主要代码
Webservices.mxml 代码如下:
Mxml代码
1. <?xml version="1.0" encoding="utf-8"?>
2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
3. <mx:WebService id="ws" wsdl="http://localhost:8080/webService/services/CompanyService?wsdl" useProxy="false" showBusyCursor="true">
4. <mx:operation name="putCompany" result="Alert.show('恭喜!添加成功','返回框',3)" fault="Alert.show('添加失败','失败',3)">
5.
6. </mx:operation>
7. <mx:operation name="getCompanyCEO" result="showInfo(event)" fault="Alert.show('失败','tile',2)">
8.
9. </mx:operation>
10. </mx:WebService>
11. <mx:XML>
12.
13. </mx:XML>
14. <mx:Script>
15. <![CDATA[
16. import mx.rpc.events.ResultEvent;
17. import mx.controls.Alert;
18. private var com:String ;
19. private var cio:String ;
20.
21. public function addCompany():void {
22. com = company.text ;
23. cio = ceo.text ;
24. ws.putCompany(com,cio);
25. }
26.
27. public function seeCeo():void {
28. var str:String;
29. str = company.text;
30. ws.getCompanyCEO(str);
31. }
32.
33. public function showInfo(event:ResultEvent):void {
34. var str:String;
35. str = event.result.toString();
36.
37. Alert.show(str,"凯旋",2);
38. }
39. ]]>
40. </mx:Script>
41.
42. <mx:Panel title="DataGrid Control Example" height="100%" width="100%"
43. paddingTop="10" paddingLeft="10" paddingRight="10">
44. <mx:Label x="10" y="10" text="公司" height="39" width="55" fontSize="21" fontWeight="bold"/>
45. <mx:TextInput x="61" y="10" height="31" id="company" fontSize="20"/>
46. <mx:Label x="10" y="66" text="老大" width="55" height="49" fontSize="21" fontWeight="bold"/>
47. <mx:TextInput x="61" y="75" height="31" id="ceo" fontSize="20"/>
48. <mx:Button label="添加" height="37" fontSize="17" id="add" click="addCompany();"/>
49. <mx:Button label="查看(输入公司查老大)" height="29" fontSize="17" id="see" click="seeCeo();"/>
50.
51. </mx:Panel>
52. </mx:Application>
<?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
Java代码
1. <?xml version="1.0" encoding="UTF-8"?>
2. <web-app version="2.4"
3. xmlns="http://java.sun.com/xml/ns/j2ee"
4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
6. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
7. <welcome-file-list>
8. <welcome-file>index.jsp</welcome-file>
9. </welcome-file-list>
10.
11. <servlet>
12. <servlet-name>XFireServlet</servlet-name>
13. <servlet-class>
14. org.codehaus.xfire.transport.http.XFireConfigurableServlet
15. </servlet-class>
16. </servlet>
17.
18. <servlet-mapping>
19. <servlet-name>XFireServlet</servlet-name>
20. <url-pattern>/servlet/XFireServlet/*</url-pattern>
21. </servlet-mapping>
22.
23. <servlet-mapping>
24. <servlet-name>XFireServlet</servlet-name>
25. <url-pattern>/services/*</url-pattern>
26. </servlet-mapping>
27.
28.
29. </web-app>
<?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 )
Java代码
1. package entity;
2.
3. import java.util.HashMap;
4.
5. public class CompanyServiceImpl{
6. HashMap<String,String> m=new HashMap<String,String>();
7. public void into(){
8. m.put("虚虚公司", "虚虚象");
9. m.put("微软", "zwh");
10. }
11. public String getCompanyCEO(String company) {
12. into();
13. return m.get(company);
14. }
15. public void putCompany(String company,String CEO){
16. m.put(company, CEO);
17. }
18.
19. }
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
Xml代码
1. <beans xmlns="http://xfire.codehaus.org/config/1.0">
2. <service>
3. <name>CompanyService</name>
4. <namespace>http://xfire.codehaus.org/CompanyService</namespace>
5. <serviceClass>entity.CompanyServiceImpl</serviceClass>
6. <!--
7. <serviceClass>entity.CompanyService</serviceClass>
8. <implementationClass>entity.CompanyServiceImpl</implementationClass>
9. -->
10. </service>
11. </beans>
<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代码
1. <?xml version="1.0" encoding="UTF-8" ?>
2. - <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">
3. - <wsdl:types>
4. - <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://xfire.codehaus.org/CompanyService">
5. - <xsd:element name="getCompany">
6. <xsd:complexType />
7. </xsd:element>
8. - <xsd:element name="getCompanyResponse">
9. - <xsd:complexType>
10. - <xsd:sequence>
11. <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string" />
12. </xsd:sequence>
13. </xsd:complexType>
14. </xsd:element>
15. </xsd:schema>
16. </wsdl:types>
17. - <wsdl:message name="getCompanyRequest">
18. <wsdl:part name="parameters" element="tns:getCompany" />
19. </wsdl:message>
20. + <wsdl:message name="getCompanyResponse">
21. <wsdl:part name="parameters" element="tns:getCompanyResponse" />
22. </wsdl:message>
23. - <wsdl:portType name="CompanyServicePortType">
24. - <wsdl:operation name="getCompany">
25. <wsdl:input name="getCompanyRequest" message="tns:getCompanyRequest" />
26. <wsdl:output name="getCompanyResponse" message="tns:getCompanyResponse" />
27. </wsdl:operation>
28. </wsdl:portType>
29. - <wsdl:binding name="CompanyServiceHttpBinding" type="tns:CompanyServicePortType">
30. <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
31. - <wsdl:operation name="getCompany">
32. <wsdlsoap:operation soapAction="" />
33. - <wsdl:input name="getCompanyRequest">
34. <wsdlsoap:body use="literal" />
35. </wsdl:input>
36. - <wsdl:output name="getCompanyResponse">
37. <wsdlsoap:body use="literal" />
38. </wsdl:output>
39. </wsdl:operation>
40. </wsdl:binding>
41. - <wsdl:service name="CompanyService">
42. - <wsdl:port name="CompanyServiceHttpPort" binding="tns:CompanyServiceHttpBinding">
43. <wsdlsoap:address location="http://localhost:8080/webService/services/CompanyService" />
44. </wsdl:port>
45. </wsdl:service>
46. </wsdl:definitions>