locked
calling a procedure with output parameter RRS feed

  • Question

  • hi to all ...

    plz help me to find a way  to call procedure with output parameter  using a web service?

     I searched a lot but i couldn't find any example ....

    thanx in advance ....

     

    Wednesday, February 18, 2009 3:37 AM

Answers

  • Hi R.yahya,

     actually I mean in IService1.cs what shall I write if I want to call a stored procedure with output parameter ...

    What do you mean by  "with output parameter"?  In IService1.cs, we need to add the interface.  For example,

        [ServiceContract]
        public interface IWCFServiceTest
        {
            [OperationContract]
            string SayHello (string name);

            [OperationContract]
            List<Person> GetPersons();
           
        }

    For more, please take a look at this video tutorial.

    Best regards,

    Jonathan

     

    Monday, February 23, 2009 9:30 PM

All replies

  • Hi,

    Call this from webservice method

     

    DataSet ds = new DataSet();

    try

    {

    SqlConnection _sqlConnection = new SqlConnection();

    _sqlConnection.ConnectionString = getConnectionString();

    _sqlConnection.Open();

    SqlCommand command = new SqlCommand();

    command.Connection = _sqlConnection;

    command.CommandType = CommandType.StoredProcedure;

    command.CommandText = "StoredProcedureNames";

    SqlDataAdapter da = new SqlDataAdapter();

    da.SelectCommand = command;

     

    da.Fill(ds);

    _sqlConnection.Close();

    return ds;

    }

    Wednesday, February 18, 2009 3:40 AM
  •  actually I mean in IService1.cs what shall I write if I want to call a stored procedure with output parameter ...

    thanx ...

     

     

     

    Sunday, February 22, 2009 4:27 AM
  • Can you show the code you have so far for your Service Reference? Do you have some functional description? I think Services should be most of time functional not technical.

    Sunday, February 22, 2009 10:28 AM
  • Hi R.yahya,

     actually I mean in IService1.cs what shall I write if I want to call a stored procedure with output parameter ...

    What do you mean by  "with output parameter"?  In IService1.cs, we need to add the interface.  For example,

        [ServiceContract]
        public interface IWCFServiceTest
        {
            [OperationContract]
            string SayHello (string name);

            [OperationContract]
            List<Person> GetPersons();
           
        }

    For more, please take a look at this video tutorial.

    Best regards,

    Jonathan

     

    Monday, February 23, 2009 9:30 PM
  • thx 4 reply...

    actually I want to save customer info to sql server ( customer name ,ID,.....) where id is an auto number (output parameter) so when I call procedure in IService what shall i write....

    thx again...

     

     

    Saturday, February 28, 2009 4:58 AM
  • Depending on your design it's good to make use of objects. Let's say a Customer object with all the properties also the ID. Depending on the type you can make the ID for example a nullable int. That would result in something like this in WCF.

     

        [ServiceContract]
        public interface ICustomerService
        {
            [OperationContract]
            Customer Save (Customer name);
        }

     Or if that would impact your design too much you can also just return the CustomerID. Something like:

        [ServiceContract]
        public interface ICustomerService
        {
            [OperationContract]
            int Save (Customer name);
        }
     
    Saturday, February 28, 2009 7:26 AM
  • thx Mark.. there was no error in IServie.cs even without useing customer as an object but when i implemented the interface in Servie.svc.cs as below I got an error says " No overload for method 'save' takes '1' arguments" . plz help.............

     IServie.cs  :

    [OperationContract]

    int save(string username);

     

    Servie.svc.cs : 

    public
    int save (string username)

    DataClasses1DataContext db = new DataClasses1DataContext();

    db.save( username);

    }

    Sunday, March 1, 2009 3:32 AM
  • This looks more like a problem in the call db.save(username);. Does it work when you comment out the call to db.save?
    Sunday, March 1, 2009 11:04 AM
  • Hi Yahya,

    public int save (string username)

    DataClasses1DataContext db = new DataClasses1DataContext();

    db.save( username);

    }

     

    There is no return here.  What's the prompt here?

    Best regards,

    Jonathan

     

    Sunday, March 1, 2009 10:52 PM