开发者

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 ca开发者_运维知识库n 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.


You don't need web service source codes. The web service can be implemented in Java. Creating service reference woks the same, as we really don't know what is on the other side.

So, try Add Service Reference in VS2008 and enter the url to working web service. VS will examine the wsdl on server and generate needed classes for you.

From than on, you just call the service as some ordinary method call. Meaning you don't have to fiddle with requests and http and such details. All that is hidden from you. Except in app.config where many WCF settings can be changed.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜