I have a SQL Server 2005 stored procedure that has a signature like this:
CREATE PROCEDURE [dbo].[ProcTRequest]
@Pxml xml, @ClientCode varchar(10)
AS
BEGIN
...
END
I’m tasked with writing an .asmx web service that will call this stored procedure. This is where I’m having a block.
If the parameter @Pxml is specified as string in the C# web method, we get
Server was unable to process request.
Then tried XmlText as the type for @Pxml, which resulted in
Server was unable to process request. Method MyWebService.MyWebMethod can not be reflected. There was an error
reflecting ‘PXml’. ->; There was an error reflecting type
‘System.Xml.XmlText’. -> System.Xml.XmlText cannot be used as: ‘xml
element’.
What is the correct way to call this stored procedure from a C# web method? Please note that the @Pxml parameter will always be a well-formed XML.
The person that will be calling this web service is using Curl on a Unix system.
Though the requirement is an ASMX, if this can be implemented via WCF, can you please show me how with a piece of pseudo code? I’m not familiar with WCF yet.
Please help. Thank you.
UPDATE: This is how I call the SP
[WebMethod]
public string GetRequestID(string PXml, string clientcode)
{
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader dr = db.ExecuteReader("ProcRequestID", PXml, clientcode))
{
return dr["RequestID"].ToString();
}
}
Couldn’t you use a string on the ASMX interface (so the caller send you a string), but inside the ASMX web service, you define the
@PXmlparameter on the stored procedure call asSqlDbType.Xml? I think that ought to work ….Something along the lines of :
Since you’re just calling the stored proc and not expecting a result set back – use
ExecuteNonQueryinstead ofExecuteReader.Also vitally important : tell ADO.NET that you’re calling a stored procedure! That’s what this line does:
Otherwise, ADO.NET by default expects to get full inline SQL statement and might just not be able to parse and execute that ….