我如何消耗返回列表的c#webMethod< lt; string>>通过我的Java客户?
我在c#中有一个ASMX Web服务,其中webmethod getKeys()
返回 list< list< string>>>
,但是当我通过我的java客户端消耗webmethod时, getKeys()
是类型对象[]
。因此,我无法找到一种访问字符串的方法。理想情况下,我想将C#列表< list< string>>
放到arraylist< string []>但是我对更轻松的解决方案开放。我需要在JTable中显示内容。
对此的任何帮助或有关如何解决这种方法的提示,将不胜感激。
这是相关方法:
public class ProgAss5WebService : System.Web.Services.WebService
{
[WebMethod]
public List<List<string>> GetKeys()
{
return dal.GetKeysList();
}
} //End of C# WebService class
public class Controller { //Java client
public void getKeys() {
ArrayList<String[]> rowList = new ArrayList<String[]>();
try {
//This works
Object[] myArr = proxy.getKeys();
//This does not
rowList = proxy.getKeys();
}catch(RemoteException e) {
e.printStackTrace();
}
}
}//End of Controller class
我仍在学习正确的方法,因此请告诉我是否需要更多信息并纠正我的问题中的任何错误。谢谢你!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 C# 方法正在后台进行反序列化和重新序列化。 Java 不知道
List
是什么,因此它将其放入对象列表中。然后您可以投射该对象列表。可能有更快/更好的方法来做到这一点,但我不是 Java 专家,这应该足够好了:>
Your C# method is being deserialized and reserialized in the background. Java does not know what a
List<List<String>>
is, so it makes it into a list of objects. You then cast that list of objects. There are probably faster/better ways to do this, but I'm not a Java expert and this should be good enough:我找到了解决问题的方法。我更改了列表&gt;进入C#锯齿状阵列,似乎与Java中的多维阵列基本相同。我尝试了使用C#多维数组的解决方案,但是我收到了一个错误的消息,该误差表示不支持多维数组(不幸的是,我没有错误的邮件副本)。
通过正确阅读文档,我发现了如何使用锯齿状阵列,从而使代码非常简单。
I found a way to solve my problem. I changed the List<List> into a C# jagged array which seems to be basically the same as a multidimensional array in Java. I tried the solution with a C# multidimensional array but I got an error messaage that said multidimensional arrays where not supported(unfortunately I don't have a copy of the error msg).
By properly reading the Documentaion I figured out how to use the jagged array which made the code very simple.