简体   繁体   English

来自C#Web Service的Java Web Service Client中的DataSet

[英]DataSet in Java Web Service Client from C# Web Service

I'm a novice in both Java and C#, so please bear with me. 我是Java和C#的新手,所以请多多包涵。

I've made a Web Service in C# with the .Net Framework that is connected to one table in my MSSQL Server database. 我已经用.Net Framework在C#中制作了一个Web服务,该服务已连接到MSSQL Server数据库中的一个表。 I've made a Java Application in Eclipse with a Web Service Client that is connected to the Web Service in Visual Studio with a SoapProxy through localhost. 我已经在Eclipse中使用Web Service客户端制作了Java应用程序,该客户端通过localhost通过SoapProxy连接到Visual Studio中的Web Service。

The problem is that the webmethod I've made in C# is returning the Library table from MSSQL as a DataSet which I have no idea how to call as a method and print in the console of my Java Client. 问题是我用C#编写的Web方法将MSSQL的Library表作为数据集返回,我不知道如何作为方法调用并在Java Client的控制台中打印。

Is there any better way going about the webmethod to get my table from MSSQL to VisualStudio and then printing it in my Eclipse Console? 有什么更好的办法可以将Web表从MSSQL移到VisualStudio,然后在Eclipse控制台中打印出来?

Java Web Service Client http://imgur.com/a/oCGzy Java Web服务客户端 http://imgur.com/a/oCGzy

C# Web Service C#Web服务

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WSDB : System.Web.Services.WebService
{

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod]
    public DataSet getBooks()
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString =  "server=.;database=Library;user=sa;password=1234";
        SqlDataAdapter da = new SqlDataAdapter("select * from Library", con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;



    }

}

What should the code in my Java Web Service Client look like to call and print this DataSet in the console the easiest most basic way? 我的Java Web Service客户端中的代码应该以哪种最简单,最基本的方式在控制台中调用和打印此DataSet? (formatting doesn't have to be pretty) (格式不必很漂亮)

Update 更新

I tried a different approach with a new WebMethod, connecting to my database with ADO.Net Entity Framework. 我使用新的WebMethod尝试了另一种方法,并使用ADO.Net Entity Framework连接到我的数据库。

But I'm still clueless how to call and print the method in my Java Web Client, any suggestions? 但是我仍然不知道如何在Java Web Client中调用和打印方法,有什么建议吗?

[WebMethod]
    public Library GetLibInfo(string booknr)
    {
        return libEnt.Libraries.Single(x=> x.booknr == booknr);
    }

I'm not ac# programmer but from what I read about Dataset I see that is a stateful object, you should only return serializable objects from a WS. 我不是ac#程序员,但是从我读到的有关数据集的内容来看,我看到这是一个有状态的对象,您应该只从WS返回可序列化的对象。

So put your result into a simple array and return that. 因此,将结果放入一个简单的数组中并返回。

Anyway you should call somethink like this: 无论如何,您应该这样称呼:

you should have something like this: 你应该有这样的东西:

WSDBLocator service = new WSDBLocator();

GetBooksReponseGetBookResults res = service.getGetBooks();

SomeKindOfCollection col = res.someMethod();
for(SomeKindOfObject o : col){
   System.out.print(o.getProperty1());
   System.out.print(",");
   System.out.print(o.getProperty2());
   System.out.print(",");
   System.out.printLn(o.getProperty3());
}

If formatting isn't an issue you can just import the data from your DataTable into an object array and return it. 如果格式化不是问题,则可以将数据从DataTable导入到对象数组中并返回。

[WebMethod]
    public object[] javaCustomer()
    {
        connectCronus();  //changes the ConnectionString 
        int count = 0;
        cmd = new SqlCommand("select [Name],[City] from [CRONUS Sverige AB$Customer];");
        dt = returnDataTable();
        object[] ar = new string[dt.Rows.Count];
        foreach (DataRow row in dt.Rows)
        {
            ar[count] = row["Name"].ToString() + "\t" + row["City"].ToString();
            count++;
        }
        return ar;
    }

Then it's just a matter of printing it in your java client. 然后,只需在Java客户端中打印即可。

for(Object o : proxy.javaEmployee()){
        System.out.println(o);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM