到网上下载axis包,执行以下命令,
set Axis_Lib=axis-1_4\lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Output_Path=.
set Package=wcf
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java http://localhost:8000/WebWcf/GetAccountService.svc?wsdl -o%Output_Path% -p%Package%
其中axis-1_4\lib是axislib相对路径,http://localhost:8000/WebWcf/GetAccountService.svc?wsdl是wcf服务路径
运行后生成wcf目录,将目录中的java代码复制到项目中,用如下代码调用:
package wcf;
public class ClientTest {
/**
* @param args
*/
public static void main(String[] args) {
try {
GetAccountService client = new GetAccountServiceLocator();
Account account = new Account();
account = client.getBasicHttpBinding_IGetAccountService().getAccount("abc");
System.out.println("account="+account.getUserid()+";"+account.getUsername());
System.in.read();
} catch (Exception e) {
System.out.println("Exception : " + e.getMessage());
}
}
}
public class ClientTest {
/**
* @param args
*/
public static void main(String[] args) {
try {
GetAccountService client = new GetAccountServiceLocator();
Account account = new Account();
account = client.getBasicHttpBinding_IGetAccountService().getAccount("abc");
System.out.println("account="+account.getUserid()+";"+account.getUsername());
System.in.read();
} catch (Exception e) {
System.out.println("Exception : " + e.getMessage());
}
}
}
不支持WSHttpBinding,
getBasicHttpBinding_IGetAccountService参数可以传递服务URL。