简体   繁体   中英

How to pass parameters to SOAP web service using asp.net mvc 4

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM