工程实践的子系统涉及到了点Axis调用ASP.NET开发的Web Service的方法,小结一下。
1- 使用.NET开发一个Web Service,并将接口写为如下方式:
[SoapRpcMethod(Action
=
"
http://www.wsscore.com/isStudentLoginSuccessful/Rpc
"
, RequestNamespace
=
"
http://www.wsscore.com/isStudentLoginSuccessful/SU
"
, ResponseNamespace
=
"
http://www.my.com/isStudentLoginSuccessful/SU
"
)]
[WebMethod]
public int isStudentLoginSuccessful( string studentID, string password)
... {
BasicStudentInfo bs = new BasicStudentInfo();
// 1:successful 0:wrong password -1:no such studentID
return bs.isLoginSuccessful(studentID,password);
}
[WebMethod]
public int isStudentLoginSuccessful( string studentID, string password)
... {
BasicStudentInfo bs = new BasicStudentInfo();
// 1:successful 0:wrong password -1:no such studentID
return bs.isLoginSuccessful(studentID,password);
}
注意[SoapRpcMethod]属性是比较重要的,涉及到RPC方式调用的Action和名字空间。
2- 使用Axis调用这个Web服务的接口:
public class DotNetWSScore ... {
public DotNetWSScore()...{}
public int isLoginSuccessful(String studentID, String password)...{
try ...{
ResourceBundle rb=ResourceBundle.getBundle("com.wsscore4student.business.service-config");
String endpoint= rb.getString("url");
System.out.println( "url is " + endpoint);
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("http://www.wsscore.com/isStudentLoginSuccessful/SU","isStudentLoginSuccessful"));
call.addParameter("studentID",org.apache.axis.encoding.XMLType.XSD_DATE,javax.xml.rpc.ParameterMode.IN);
call.addParameter("password",org.apache.axis.encoding.XMLType.XSD_DATE,javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.wsscore.com/isStudentLoginSuccessful/Rpc");
int k = (Integer)call.invoke(new Object[]...{studentID,password});
System.out.println( "result is " + k + ".");
return k;
}
catch (Exception e) ...{System.err.println(e.toString());}
return -1;
}
}
这里我把发布.NET Web服务的url放在了com.wsscore4student.business.service-config.properties里面,本地包里的一个属性文件而已~ 动态读取,方便配置~
现在就可以实现Axis对.NET Web Service的调用了。
希望对大家有些用。