Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
SQL
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



C#
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for MyWebService
/// </summary>
[WebService(Namespace = "http://amiressami.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
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"; //OK
        }
        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
Posted
Comments
[no name] 6-Sep-14 10:05am    
your webmethod should be static

1 solution

Change your webmethod from
C#
[WebMethod]
    public string Upload(string WarrantyCode, string Serial, string ProductTitle, string ShopCenter, string AddDate, string Bill)
    {


to
C#
[WebMethod]
    public static string Upload(string WarrantyCode, string Serial, string ProductTitle, string ShopCenter, string AddDate, string Bill)
    {
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900