Consume web-service in ASP.NET MVC

Asked

Viewed 5,213 times

2

I need to consume some methods on my page through a web-service. This web-service is in Europe.

What is the best way to do it? What are End-Points?

  • Dear @pnet, if you haven’t solved any of these ways but solved another one, then please post as solved. If you have solved following any of the answers given, please, then mark as accepted answer the one that helped you solve the problem. Thank you!

2 answers

8

According to the website http://www.ehow.com/info_12212371_definition-service-endpoint.html, one endpoint is defined in the text translated below:

A endpoint is a connection point from which HTML or dynamic files are exposed. Endpoints provide information needed to access a Webservice. The endpoint provides a reference or specification that is used to define a group or family of message addressing properties and give point-to-point message characteristics, such as references to the origin and destination of the terminals, as well as the identity of messages to allow uniform addressing of "independent" messages. The endpoint can be a PC, PDA, or point-of-sale terminal.

In your case, the endpoint is the very Webservice address you want to access.

To add a Webservice to your application, do the following:

Step 1

Right click on the project > Add > Service Reference

Passo 1

Step 2

On this screen, click Advanced

Passo 2

Step 3

Click on Add Web Reference...

Passo 3

Step 4

Paste the Webservice address you want to access in the field URL. If you are really a Webservice with a valid WSDL, the methods will appear in the bottom square. Just click on Add Reference that will be added to your project a class representing access to the Webservice.

Passo 4

Consuming the Webservice

To access your Webservice data in Controller, use a statement more or less like this:

var wsMeuWebService = new wsMeuWebService.MeuWebService();
wsMeuWebService.MetodoDoWebService();
  • I use Visual Studio 2013

  • @pnet Atualizada.

  • 1

    @pnet, it seems to me that this answer is fully valid. If it is, mark as correct.

  • For me generate task-based Operation this disabled... it may interfere in something?

  • Operations are not treated as asynchronous, simply. If your application is asynchronous it may even interfere, but it is not a problem.

0

Do the following, right-click the project and choose the option Adicionar referência de serviço.

Paste the WS URL, change the namespace and press OK.

  • Cool and thank you for the gift. My question is this. WS has 3 end-points. See the guys' ticket. In order to perform the Search, Booking, Payment, File Query, among others, you need to have a session on the webservice. Sessions are created by the Createsession() method, available in the Common endpoint. The return of this method is a string, which we will call sessionId. This sessionId is required in virtually all Webservice methods. The Createsession() method takes an object of type Userauthtokensv1.

  • I am following your example. The question is, I need to load the result in cshtml, via jquery and ajax, to avoid loading the whole page. How do I do it? All or most of it is there. No jquery

  • Actually it’s like this. This method will bring me an array of strings or objects, I don’t know yet, but I think it’s string. I need to do each in jquery and populate in the right places. If you see more than one item, go creating DIV’s and putting the text and the menu on the right, go mounting a link. In reality it is an array of hotels, categories, in a room and the categories (stars) go riding in the panel to the right. That’s what I need to do with jquery.

  • So enlighten me one thing, you don’t want to call it in code, you want to call the Web Service via Ajax, right?

  • Yes. I’ve even started my own jquery. Only the skeleton, like this: Function Pegahotelpackage() { $.ajax({ url: '/Step/Pegahotelpackage', dataType: "json", contenttype: "application/json; charset=utf-8", type: "POST", sucess: Function (date) { }, error: Function (error) { } }); }. My method in the controller is that it is bone, but it lacks more information of the manager. Played in the air and left.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.