最近,有个项目需要用到WebService的一些调用.对方的Webservice服务程序是用JAVA开发的,现在要在C#中调用.一般的类型数据还可以,但遇到了map类型的数据到是费了不少的周折,下面就将具体实现写出来与大家一起讨论.
定义访问对象:UserService.FaxUserService service = new UserService.FaxUserService();
验证: service.Credentials = new System.Net.NetworkCredential("053188113396","000000");
1、修改访问的代理类:
修改URL(包括Map和MapItem):http://xml.apache.org/xml-soap1如:
[System.Xml.Serialization.SoapTypeAttribute("Map", "http://xml.apache.org/xml-soap1")]
public class Map {
/// <remarks/>
public mapItem[] item;
}
修改各Map类型的函数返回类型如:
public object faxRec(string agentID, string userID, string startTime, string endTime) {
object[] results = this.Invoke("faxRec", new object[] {
agentID,
userID,
startTime,
endTime});
return ((object)(results[0]));
}
2、对修改后的函数调用:
System.Xml.XmlElement erm=null;
string tmpstr=null;
System.Array tmpary=(System.Array)service.faxRec(this.AgentID,this.UserID,startTime,endTime);
int pm=tmpary.Length-1;
for(int i=6;i<=pm;i++)
{
erm=(System.Xml.XmlElement)tmpary.GetValue(i);
tmpstr=erm.InnerText;
this.add_table(tmpstr); //插入到数据表格中
}