【问题标题】:is WCF useful to build a client that uses a non-WCF web service?WCF 对构建使用非 WCF Web 服务的客户端有用吗?
【发布时间】:2009-08-08 22:42:03
【问题描述】:

我是 WCF 的新手,对 Web 服务的编码经验有限。

在工作中,所有面向网络服务的事情都被要求使用 WCF。我需要做的工作是查询一个非 WCF Web 服务,它显然是用 Java 构建的,带有一个 Netscape 证书服务器和相关的基础设施(该服务不在我们的控制之下)。我有 Web 服务的 WSDL。

  1. WCF 是否为这项工作增加了任何价值?

  2. 针对非 WCF 服务构建 WCF 客户端是否合理、正常或最佳做法?

  3. 任何人都可以提供任何建议吗?

谢谢!!!

【问题讨论】:

    标签: wcf web-services


    【解决方案1】:

    是的,WCF 客户端可以针对使用其他技术或平台创建的 Web 服务工作。这是相当普遍的。使用 Visual Studio,客户端代理代码是从 WSDL 为您生成的,您可以像调用本地代码一样调用远程服务。

    不要无耻地插入,这里有一个WCF client calling the Amazon S3 web service 的示例,它肯定不是用.NET 构建的。该示例演示了创建 WCF 客户端时的典型工作流程:

    1. 通过将 Visual Studio 指向 WSDL URL,将 服务引用 添加到 Web 服务。您无需在此步骤中编写任何代码。

    2. 从您的代码中调用 Web 服务。在下面的代码中,AmazonS3Client 类是由 Visual Studio 在上面的步骤 1 中创建的。输入 client.ListAllMyBuckets 来调用该服务时,您将获得完整的智能感知。

    static void Main(string[] args) {  
        DateTime       now    = LocalNow();  
    
        // create the web service client object
        AmazonS3Client client = new AmazonS3Client();  
    
        // invoke the web service
        var result = client.ListAllMyBuckets(  
            accessKeyId,  
            now,  
            SignRequest(secretAccessKey, "ListAllMyBuckets", now));  
    
        // show the results returned from the web service
        foreach (var bucket in result.Buckets) {  
            Console.WriteLine(bucket.Name);  
        }  
    }  
    

    【讨论】:

    • 1:漂亮的企鹅 2:不要羞于无耻的插件 :-) 3:非常感谢您的帮助,这看起来是我需要去的方向
    【解决方案2】:

    请参阅发布在http://justcompiled.blogspot.com/2010/10/building-web-service-client-with-wcf.html 的文章,主题为“使用 WCF 构建 Web 服务客户端”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多