Jordan
Jordan

Reputation: 2758

Consuming a webservice within a local application

I have an asp.net web service that I want to consume from another asp.net page on the same server.

The reason is that I am using Ajax to validate if a username is taken and if they submit anyway. Rather than rewrite the code in a local function i'd like the server to be able to call the webservice but when I register it under service references I get some funny things like

GetUsernameAvailableRequest
GetUsernameAvailableRequestBody

etc instead of just a function to call.... does anyone know what I am doing wrong here? Is it possible to call a webservice like a local function in my project or do I need to make a new function with the same functionality?

Upvotes: 1

Views: 2229

Answers (3)

John Saunders
John Saunders

Reputation: 161773

Look in the object browser to see all the generated classes. One of them will be something like myserviceSoapClient. That's the object you have to create an instance of. It will have the methods to call the service.

Upvotes: 0

Darbio
Darbio

Reputation: 11418

Yes it is entirely possible (and even recommended architecture).

Make sure you have added the webservice as a WebService in VS, it will then work the proxy type creation from the WSDL automagically.

You will need to instantiate your webservice, and then you can use the methods exposed on your method.

E.g.

using (WebServiceType service = new WebServiceType()){
    string result = service.Method();
}

Assuming you have a Method called Method() and your service type is WebServiceType

Upvotes: 3

Felix Martinez
Felix Martinez

Reputation: 3978

I can't tell you why It happens that way, but that did happen to me on a project I was working on. You can see the related question I asked.

FYI; I believe that you have a GetUsernameAvailableResponse object, where you'll find inside an object with the response you want.

Upvotes: 0

Related Questions