Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
When I check the url in my browser my web service work correctly but when I call my link from my store procedure throw exception like this

System.InvalidOperationException: Request format is invalid: .
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()


my web service is:

C#
[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();
       }
   }


and my store procedure is:

SQL
CREATE PROC Upload
AS
DECLARE @WarrantyCode AS NVARCHAR(20)
DECLARE	@Serial AS NVARCHAR(50) 
DECLARE	@ProductTitle AS NVARCHAR(50) 
DECLARE	@ShopCenter AS NVARCHAR(70) 
DECLARE	@AddDate AS NVARCHAR(50) 
DECLARE	@Bill AS NVARCHAR(50) 



SET     @WarrantyCode = '123456'
SET	@Serial = '123456'
SET	@ProductTitle= '123456' 
SET	@ShopCenter= '123456'
SET	@AddDate = '2014-01-01'
SET	@Bill = '123456'


Declare @Obj as Int;
Declare @Uri as Varchar(8000);
Declare @Response as Varchar(8000);
DECLARE @hr AS INT
 
 
    SET @Uri = 'http://MY IP GOES HERE:9671/MyWebService.asmx/Upload?WarrantyCode=' + @WarrantyCode + '&Serial=' + @Serial + '&ProductTitle=' + @ProductTitle + '&ShopCenter=' + @ShopCenter + '&AddDate=' + @AddDate + '&Bill=' + @Bill   
    EXEC sp_OACreate 'MSXML2.ServerXMLHttp.3.0', @obj OUT
    EXEC sp_OAMethod @obj, 'open', NULL, 'POST', @Uri, false
    EXEC sp_OAMethod @obj, 'send'
    EXEC sp_OAGetProperty @obj, 'ResponseText', @Response OUTPUT
 
       SELECT @Response AS [response], CHARINDEX('amiressami.com', @Response) AS IsOK, CHARINDEX('Hello', @Response) AS Result
    EXEC sp_OADestroy @obj

RETURN

created link by my SP is:

http://MY IP:9671/MyWebService.asmx/Upload?WarrantyCode=123456&Serial=123456&ProductTitle=123456&ShopCenter=123456&AddDate=2014-01-01&Bill=123456

it work on browser correctly but in SP not work
Posted
Updated 3-Sep-14 1:32am
v2
Comments
Kornfeld Eliyahu Peter 3-Sep-14 7:06am    
You may have an encoding problem? Try to sniff into HTTP with a tool like Fiddler...
Roozbeh Amiressami 6-Sep-14 3:50am    
hii think this link is better than this:

http://www.codeproject.com/Questions/815843/Why-My-Webservice-Throw-Exception-When-I-Execute-M?arn=0
ZurdoDev 3-Sep-14 7:31am    
I'd suggest debugging your stored procedure.
[no name] 3-Sep-14 7:53am    
Storing DateTimes as strings is just begging for trouble.
Thomas Nielsen - getCore 4-Sep-14 5:36am    
The genereated link, what is those semicolons doing there, cannot really see what place they have in your querystring? Looks like your adddate and addbill QS parameters are not written like they should

1 solution

What is the exact error, trace the error by using the try-catch block.
 
Share this answer
 
v2
Comments
Roozbeh Amiressami 6-Sep-14 3:51am    
i think this link can describe my error better


http://www.codeproject.com/Questions/815843/Why-My-Webservice-Throw-Exception-When-I-Execute-M?arn=0

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