如何在 Windows 8.1 应用程序和 Windows Phone 8 应用程序中使用 SOAP? [英] How to use SOAP in Windows 8.1 apps and in Windows Phone 8 apps?

查看:47
本文介绍了如何在 Windows 8.1 应用程序和 Windows Phone 8 应用程序中使用 SOAP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一些方法可以在 .net-4.5 中创建 SOAP 请求和获取 SOAP 响应?如果有必要,我应该安装哪些扩展?

Is there some methods to create SOAP-requests and to get SOAP-responses in .net-4.5? Which extentions I should to install, if it's necessary?

推荐答案

您可以通过 Visual Studio 中的添加服务引用"功能使用 SOAP 服务.在幕后,这将调用 svcutil.wsdl 转换为 .cs 服务原型.

You can use SOAP services via the "Add Service Reference" function in Visual Studio. Behind the scenes, this will call svcutil to convert the .wsdl into .cs service prototypes.

.Net Framework 包括 WCF,这是较新的和推荐的网络通信框架,以及 .Net Remoting,它与一些非 .Net SOAP 端点更兼容.

The .Net Framework includes both WCF, which is the newer and recommended network communication framework, as well as .Net Remoting, which is more compatible with some non-.Net SOAP endpoints.

  • Introduction to WCF (MSDN)
  • This answer to a similar question addressing WCF from a SOAP perspective
  • Walkthrough: Creating and accessing WCF Services (MSDN)
  • what is WSDL URI in WCF?
  • Adding Custom [SOAP] MessageHeaders to a WCF Call (MSDN Blog)

对于位于 http://www.webservicex.net/currencyconvertor.asmx?WSDL:

  • 生成客户端代理
    svcutil http://www.webservicex.net/currencyconvertor.asmx?WSDL
  • 重命名生成的配置
    move output.config program.exe.config
  • 创建一个测试客户端:

Program.cs:

using System;
using www.webservicex.net;

class Program
{
    public static void Main(string[] args)
    {
        var client = new CurrencyConvertorSoapClient("CurrencyConvertorSoap");
        var conv = client.ConversionRate(Currency.USD, Currency.EUR);
        Console.WriteLine("Conversion rate from USD to EUR is {0}", conv);
    }
}

  • 编译
    csc Program.cs CurrencyConvertor.cs
  • 运行:
    c:Dropsoaptest>Program.exe
    从美元到欧元的转换率为 0.7221
  • 这篇关于如何在 Windows 8.1 应用程序和 Windows Phone 8 应用程序中使用 SOAP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆