--------------------------------------------------------------------------
一下内容为一个flex写的一个客户端的代码。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
public function getSuccess(evt:ResultEvent):void
{
trace(evt.result as String);
txtOUT.text=evt.result.toString();
}
public function getFault(evt:FaultEvent):void
{
Alert.show(evt.message.toString(),"提示");
}
]]>
</mx:Script>
<mx:WebService id="java_webservice" wsdl="http://localhost:8080/flexWS_server?wsdl"
useProxy="false">
<mx:operation name="getAnswer"
result="getSuccess(event);"
resultFormat="object"
fault="getFault(event);">
<mx:request>
<arg0>{txtIN1.text}</arg0>
<arg1>{txtIN2.text}</arg1>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:Canvas x="64" y="37" width="498" height="292" backgroundColor="#924A15">
<mx:Button x="305" y="32" label="计算" width="71"
height="36" fontSize="14" id="btn"
click="java_webservice.getAnswer.send()"/>
<mx:TextInput x="31" y="32" width="93" height="36"
backgroundColor="#F9F9FA" color="#F97001"
fontSize="15" id="txtIN1"/>
<mx:TextArea x="31" y="76" width="457" height="206"
fontSize="15" id="txtOUT"/>
<mx:TextInput x="170" y="36" width="93" height="36"
backgroundColor="#F9F9FA" color="#F1571A"
fontSize="15" id="txtIN2"/>
<mx:Label x="132" y="32" text="X" width="30" fontSize="28"
color="#F5F9FA"/>
</mx:Canvas>
</mx:Application>
--------------------------------------------------------------------------
一下为要暴漏的接口,简单的加法Test.java
package fu.flexws;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface Test {
@WebMethod
public String getAnswer(int i,int j);
}
--------------------------------------------------------------------------
上面接口的实现TestImpl.java
package fu.flexws;
import javax.jws.WebMethod;
import javax.jws.WebResult;
public class TestImpl implements Test {
@WebMethod
public String getAnswer(int i,int j) {
System.out.println("两个数相乘的结果是"+i*j);
return String.valueOf(i*j);
}
}
------------------------------------------------------------------
发布服务:
MainServer.java
package fu.flexws;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
public class MainServer {
public static void main(String[] args){
JaxWsServerFactoryBean factory=new JaxWsServerFactoryBean();
factory.setAddress("http://localhost:8080/flexWS_server");
factory.setServiceClass(TestImpl.class);
Server server=factory.create();
System.out.println("服务器端启动了···············");
server.start();
}
}
完了最后,运行客户端,输入相应的值之后,即可以看见结果出现在控制台上。调用的webservice服务是成功。
但是,结果却没有返回,不会出现在客户端的界面上,请读者帮忙分析和研究下。
***注意:需要CXF中的lib目录下面的所有jar包,jdk1.6