0

好的,自从我使用 Web References 以来已经有一段时间了。我需要复习一下。我想我有大约 80% 的代码需要得到响应,但我错过了一些东西。也许你可以帮助我:)

给定:指向url时在方法列表中
调用的 web 方法。GetSomething.wsdl

这会产生一些类/对象:

  • GetSomethingRequest
  • GetSomethingCompletedEventHandler
  • GetSomethingCompletedEventArgs
  • myComplexType

我用来创建此代码:

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;
}

我究竟做错了什么?我错过了什么?提前致谢。

4

2 回答 2

0

您不需要 Web 服务源代码。Web 服务可以用 Java 实现。创建服务引用也是一样的,因为我们真的不知道另一边是什么。

因此,尝试在 VS2008 中添加服务引用并输入工作 Web 服务的 url。VS 将检查服务器上的 wsdl 并为您生成所需的类。

从那时起,您只需将服务作为一些普通的方法调用来调用。这意味着您不必摆弄请求和 http 以及此类详细信息。对你隐藏的一切。除了在 app.config 中可以更改许多 WCF 设置。

于 2011-02-24T21:58:02.557 回答
0

好的,我发现我需要找到一个Service类型类。请参阅此SO Post,其中提到:

private com.nowhere.somewebservice ws;

问题是他们提供的课程对我来说不是智能感知的,我认为这不是我想要的。

以下是我将如何解决我的问题:

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);
于 2011-02-24T22:27:03.627 回答