Search code examples
c#asynchronousdelegateswsdlweb-reference

Need some help with code for getting a response from a Web service. Can you help me connect the dots?


Ok, its been a while since I've worked with a Web References. I need a refresher. I think I have about 80% of the code I need to get a response going but I'm missing something. Maybe you can help me :)

Given:
A web method called GetSomething in the list of methods when pointing to a .wsdl url.

This produces a few classes/objects:

  • GetSomethingRequest
  • GetSomethingCompletedEventHandler
  • GetSomethingCompletedEventArgs
  • myComplexType

Which I use to create this code:

void someMethodToTestResponse()
{
    GetSomethingRequest request = new GetSomethingRequest();

    // fill in the request
    request.myComplexType.Property1 = "Blah";
    request.myComplexType.Property2 = "Kachoo";

    GetSomethingCompletedEventHandler handler = GetSomethingCompleted_Response;

    //.... ok now what?
    //handler.Invoke(???)
    // at this point I'm supposed to send an object for source (request maybe?)
    // and a new instance of GetSomethingCompletedEventArgs but that class is
    // asking for stuff that makes me think that is not the right idea.

}

void GetSomethingCompleted_Response(object source, GetSomethingCompletedEventArgs args)
{
    // get the result
    var result = args.Result;
}

What am I doing wrong? What am I missing? Thanks in advance.


Solution

  • Ok, I figured out that I needed to find a Service type class. See this SO Post where it mentions:

    private com.nowhere.somewebservice ws;
    

    The issue was that the class they provide wasn't intellisensing for me and I figured it wasn't what I was looking for.

    Here is how I would solve my problem:

    blah.webservice.SomeMainServiceClass service = new SomeMainServiceClass();
    GetSomethingRequest request = new GetSomethingRequest();
    
    // fill in the request
    request.myComplexType.Property1 = "Blah";
    request.myComplexType.Property2 = "Kachoo";
    
    object myResponse = service.GetSomething(request);