How to use SOAP in Windows 8.1 apps and in Windows Phone 8 apps?

余生长醉 提交于 2020-01-22 03:10:08

问题


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?


回答1:


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] MessageHeaders 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


来源:https://stackoverflow.com/questions/23124891/how-to-use-soap-in-windows-8-1-apps-and-in-windows-phone-8-apps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!