DECLARE @WarrantyCode AS NVARCHAR(20)
DECLARE @Serial AS NVARCHAR(50)
DECLARE @ProductTitle AS NVARCHAR(50)
DECLARE @ShopCenter AS NVARCHAR(70)
DECLARE @AddDate DATE
DECLARE @Bill AS NVARCHAR(50)
SET @WarrantyCode = '123456rrrrrrrr'
SET @Serial = '123456rrrxxx'
SET @ProductTitle= '123456'
SET @ShopCenter= '123456'
SET @AddDate = '2014-01-01'
SET @Bill = '123456'
DECLARE @url as nvarchar(256)
Declare @Obj as Int;
Declare @Response as Varchar(8000);
DECLARE @hr AS INT
DECLARE @src AS VARCHAR(MAX)
DECLARE @desc AS VARCHAR(MAX)
SET @url = 'http://MY IP:9671/MyWebService.asmx/Upload?WarrantyCode=' + @WarrantyCode + '&Serial=' + @Serial + '&ProductTitle=' + @ProductTitle + '&ShopCenter=' + @ShopCenter + '&AddDate=' + CAST(@AddDate AS NVARCHAR(20)) + '&Bill=' + @Bill
Exec @hr=sp_OACreate 'MSXML2.XMLHTTP', @Obj OUT
EXEC sp_OACreate 'MSXML2.ServerXMLHttp.3.0', @obj OUT
EXEC sp_OAMethod @obj, 'open', NULL, 'POST', @url, false
EXEC sp_OAMethod @obj, 'send'
EXEC sp_OAGetProperty @obj, 'ResponseText', @Response OUTPUT
SELECT @url AS URL, @Response AS [response], CHARINDEX('amiressami.com', @Response) AS IsOK, CHARINDEX('Hello', @Response) AS Result
EXEC sp_OADestroy @obj
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://amiressami.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MyWebService : System.Web.Services.WebService
{
[WebMethod]
public string Upload(string WarrantyCode, string Serial, string ProductTitle, string ShopCenter, string AddDate, string Bill)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = new SqlConnection(Roozbeh.CnnStr);
cmd.CommandText = "INSERT INTO Guarranty VALUES (@WarrantyCode, @Serial, @ProductTitle, @ShopCenter, @AddDate, 1, @Bill)";
cmd.Parameters.AddWithValue("@WarrantyCode", WarrantyCode);
cmd.Parameters.AddWithValue("@Serial", Serial);
cmd.Parameters.AddWithValue("@ProductTitle", ProductTitle);
cmd.Parameters.AddWithValue("@ShopCenter", ShopCenter);
cmd.Parameters.AddWithValue("@AddDate", AddDate);
cmd.Parameters.AddWithValue("@Bill", Bill);
try
{
cmd.Connection.Open();
cmd.ExecuteNonQuery();
return "Roozbeh";
}
catch (Exception ex)
{
return ex.Message;
}
finally
{
cmd.Connection.Close();
}
}
}
When I execute my SQL Server QUERY I got the posted url and XML result posted by my web service in my query analyzer
so I have the generated url by my query same as:
http://MY IP:9671/MyWebService.asmx/Upload?WarrantyCode=123456rrrrrrrr&Serial=123456rrrxxx&ProductTitle=123456&ShopCenter=123456&AddDate=2014-01-01&Bill=123456
and my result always is:
System.InvalidOperationException: Request format is invalid: .
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
but when I copy the generated query to my browser its work without any problem