[英]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.