如何在Windows 8.1应用程序和Windows Phone 8应用程序中使用SOAP? [英] How to use SOAP in Windows 8.1 apps and in Windows Phone 8 apps?
问题描述
是否有一些方法可以在.net-4.5中创建SOAP请求并获得SOAP响应?
您可以通过以下位置的添加服务引用功能使用SOAP服务:
视觉工作室。在后台,这将调用 svcutil
将 .wsdl
转换为 .cs
服务原型。
.Net框架包括WCF(这是较新的和推荐的网络通信框架)以及.Net Remoting(这是与某些非.Net SOAP端点更加兼容。
请参见
- < a href = http://msdn.microsoft.com/zh-cn/library/dd936243.aspx rel = nofollow noreferrer> WCF(MSDN)简介
- 这个答案是从SOAP角度解决WCF的类似问题
- < a href = http://msdn.microsoft.com/zh-cn/library/bb386386.aspx rel = nofollow noreferrer>演练:创建和访问WCF服务(MSDN)
- WCF中的WSDL URI是什么?
- 添加自定义[SOAP]
MessageHeader
到WCF呼叫(MSDN博客)
示例
用于位于
- 生成客户端代理
svcutil http://www.webservicex.net/currencyconvertor.asmx?WSDL
- 重命名生成的配置
移动输出。 config program.exe.config
- 创建测试客户端:
Program.cs :
使用系统;
使用www.webservicex.net;
类程序
{
public static void Main(string [] args)
{
var client = new CurrencyConvertorSoapClient( CurrencyConvertorSoap);
var conv = client.ConversionRate(Currency.USD,Currency.EUR);
Console.WriteLine(从USD到EUR的转换率为{0},转换);
}
}
- 编译
csc Program.cs CurrencyConvertor.cs
- 运行:
c:\Drop\ \soaptest> Program.exe
从美元到欧元的转换率是0.7221
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?
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.
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.
See
- 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]
MessageHeader
s to a WCF Call (MSDN Blog)
Example
For the service located at http://www.webservicex.net/currencyconvertor.asmx?WSDL:
- Generate the client proxy
svcutil http://www.webservicex.net/currencyconvertor.asmx?WSDL
- Rename the config produced
move output.config program.exe.config
- Create a test client:
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);
}
}
- Compile
csc Program.cs CurrencyConvertor.cs
- Run:
c:\Drop\soaptest>Program.exe
Conversion rate from USD to EUR is 0.7221
这篇关于如何在Windows 8.1应用程序和Windows Phone 8应用程序中使用SOAP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!