简体   繁体   English

如何从Java客户端向C#Web服务发送数据

[英]How to send data to c# web service from java client

I am teaching myself Java, i am experienced with C/C++ and C#. 我在自学Java,对C / C ++和C#很有经验。

I have a web service in C# which has a function to insert a record into my database, simply a username and password. 我在C#中有一个Web服务,该服务具有将记录插入到数据库中的功能,只需输入用户名和密码即可。

    [WebMethod]
    public string InsertNewUser(string username, string password)
    {
        try
        {
            conn.Open();

            string insertQuery = "INSERT INTO Accounts(Username, Password) VALUES ('" + username + "','" + password + "')";

            SqlCommand cmd = new SqlCommand(insertQuery, conn);

            try
            {
                cmd.ExecuteNonQuery();
                conn.Close();
                return "New user added: " + username;
            }
            catch
            {
                return "Error in command execution";
            }
        }
        catch
        {
            return "Error in database connection";
        }
    }

Can anyone tell me if its possible to call this function in a java client side application? 谁能告诉我是否有可能在Java客户端应用程序中调用此函数? if so how do i go about it? 如果是这样,我该怎么办? Im having trouble finding much online about java connecting to c# web serivces. 我在网上找不到有关连接到C#Web服务的Java的麻烦。

At the moment i am using an asmx web service, but thinking about using WCF instead, would this make it easier or harder? 目前,我正在使用asmx Web服务,但考虑使用WCF,这会使它变得更容易或更困难吗?

Any help is greatly appreciated. 任何帮助是极大的赞赏。

Thanks 谢谢

A web service is a web service. Web服务是Web服务。 That means you can call it from anywhere. 这意味着您可以从任何地方调用它。 Be it from C#, Java or anywhere else. 无论是C#,Java还是其他任何地方。 The question is how you are exposing your web service. 问题是您如何公开您的Web服务。 I recommend exposing it as a REST service, that way it will be accessible from everywhere. 我建议将其作为REST服务公开,这样可以从任何地方访问它。 There is plenty of information available on the web on how to implement RESTful services. Web上有很多有关如何实现RESTful服务的信息。 There is even a book, RESTFul .Net, that you can read. 甚至还有一本书,RESTFul .Net,您都可以阅读。 Once you implement the REST service, then you access it using HTTP GET, PUT, UPDATE, ETC... from your choice of environment. 实施REST服务后,您可以根据环境选择使用HTTP GET,PUT,UPDATE,ETC ...访问它。

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

相关问题 如何创建客户端 web 服务,该服务将带有安全令牌的数据发送到另一个 soap web 服务 - How to create a client web service that send data with secure token to another soap web service in C#? 如何将数据从iOS发送到C#Web服务 - How to send data from iOS to c# web service 来自C#Web Service的Java Web Service Client中的DataSet - DataSet in Java Web Service Client from C# Web Service C# 客户端 Java Web 服务 - 数据互操作性问题 - C# client for Java Web Service - data interoperability issue Java Web服务将数据发送到C#客户端的最佳方法 - Best approach for Java web service sending data to C# client C#soap Web服务和Java客户端 - C# soap web service and Java client 如何将DateTime从C#代理客户端传递到仅接受日期和时间的Java Web Service - How to pass DateTime from C# proxy client to Java Web Service accepting as Date and Time only 如何使用C#直接从Web服务发送和接收数据? - How could I use C# to send and receive data from Web Service directly? 如何在没有来自C#控制台应用程序数据的情况下向Web服务发送POST请求? - How to send a POST Request to a web service without data from console application in C#? 如何使用C#的客户端证书调用Web服务? - How to call web service with client certificate from C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM