0

I want to pass parameters to method in SOAP web service. When an user adds a booking, I want to call smsSend() method in web service.

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult AddBooking(booking bk)
    {
        if(ModelState.IsValid)
        {                
            db.bookings.Add(bk);
            db.SaveChanges();
            return RedirectToAction("Index", "Home");
        }
        return View(bk);
    }

I have done lot of googling but nothing worked for me.How do I do that can someone help me to pass parameters to web service.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
hmal
  • 5
  • 1
  • 5

1 Answers1

0

If you are using Visual Studio, you can add a Service Reference to the external service. Visual Studio will create strongly-typed C# bindings to the reference. You will need the URL of the SOAP service to add it. See the Stack Overflow question here (the process is the same for Web Apps):

How to add a web service reference in Visual Studio 2015 to a console app

The link to the MSDN documentation for the process is here:

https://msdn.microsoft.com/en-us/library/bb628652.aspx

Once you have added the Service Reference, you can use the service by simply adding a using directive containing the namespace you set when you added the service and using the bindings that Visual Studio made for you.

If you do not see Add Service Reference, you may be using a .Net Core project which may not have this ability.

Edited to add information on the specific service you linked:

using SmsTest.SmsService;

namespace SmsTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var msg = "Your SMS Message";
            var serviceProviderId = 42;

            // Use the constructor overloads for ServiceClient to configure how to connect
            var service = new MyServiceClient();
            service.smsSend(serviceProviderId, msg);
        }
    }
}

This is using the information you provided with my program's default namespace as SmsTest and the Service Reference's namespace as SmsService.

Community
  • 1
  • 1
Josh K
  • 765
  • 3
  • 11
  • The bindings that Visual Studio created should have classes with methods to call the service. Those methods should have parameters that allow you to pass data to the specific method as defined by what the web service expects. If you gave us the URL of the SOAP service or documentation for it, we may be able to help a little more. – Josh K Jul 10 '16 at 06:17
  • `public ActionResult AddBooking(booking bk) { if(ModelState.IsValid) { db.bookings.Add(bk); db.SaveChanges(); var msg = "Your Service has been booked by "+bk.tContactNum; var emID = bk.SE_ID; var service = new GuideMeService(); service.smsSend(emID,msg); return RedirectToAction("Index", "Home"); } return View(bk); }` is my answer,but it shows it has some invalid arguments – hmal Jul 10 '16 at 07:12
  • The service provider ID should be an integer, assuming SE_ID is one. I'm not sure exactly what it specifies, but you can check their documentation. Otherwise, checkout the overloads for the client constructor, there might be some connection information you need to pass to get it to connect. – Josh K Jul 10 '16 at 07:17