我曾使用此查询在本地系统中调用Web服务..我收到响应为" NULL"
网络服务工作正常....
DECLARE @obj INT
DECLARE @sUrl VARCHAR(200)
DECLARE @response VARCHAR(8000)
SET @sUrl = 'http://localhost/MyWorks/SampleWebService.asmx/HelloWorld'
EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
EXEC sp_OAMethod @obj,'Open',NULL,'GET',@sUrl,false
EXEC sp_OAMethod @obj,'send'
EXEC sp_OAGetProperty @obj,'responseText',@response OUT
SELECT @response [response]
EXEC sp_OADestroy @obj
网络服务代码:
public class SampleWebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
string conString = ConfigurationManager.ConnectionStrings["rajeevConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
SqlCommand cmd = new SqlCommand("update Employees set FirstName = 'Jhon' where ID=7", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
return "Updated";
//sending the mail code.
}
}