利用PocketSOAP連結webservice(1)---.net

來源:互聯網
上載者:User
web|連結 PocketSOAP
This is a SOAP client COM component for the Windows family, originally targeted at PocketPC (hence the name), there is also a Win32 version that works on Windows 95/98/Me/NT4/2000/XP. The package includes a HTTP transport for making HTTP based SOAP requests, however the transport is separate from the main SOAP core, so any other transports can be easily added. James Clark's excellent Expat XML Parser is used for parsing the response SOAP messages.
如果你想執行文章中給出了代碼你需要下載並安裝pocketsoap
至於如何建立webservice我就不費力氣講了,今天的主要目的是如何利用pocketsoap使一些事情變得簡單。
1.在.net中使用PocketSOAP
如果在安裝PocketSoap的過程中是根據系統預設選項的話那麼在“c:\program files\simonfell\pocketSOAP1.2\”中你就會發現psoap32.dll檔案
我們需要匯入這個PocketSOAP NAMESPACE
例如:
using PocketSOAP;using System;public class test{    public static void Main(string[] args)    {        Console.WriteLine("Starting C# PocketSOAP for echoString");        CoEnvelope soap=new CoEnvelope();        HTTPTransport h=new HTTPTransport();        soap.MethodName="echoString";        soap.URI="urn:xmethodsInterop";        soap.Parameters.Create("inputString", "Hello World", "", null, null);        h.SOAPAction = "http://soapinterop.org/" ;        h.Send ( "http://www.whitemesa.net/interop/std", soap.Serialize() );        soap.Parse(h, null);        Console.WriteLine(soap.Parameters.get_Item(0).Value);    }}
編譯的時候加入PocketSOAP.dll
csc test.cs /r:pocketSOAP.dll
例子2:
using PocketSOAP;using System;public class test{    public static void Main(string[] args)    {        Console.WriteLine("Starting C# PocketSOAP for echoStringArray");        CoEnvelope soap = new CoEnvelope();        HTTPTransport h = new HTTPTransport();        soap.MethodName = "echoStringArray";        soap.URI        = "http://soapinterop.org/";                Object[] sa = new Object[2];        sa[0] = "hello";        sa[1] = "goodbye";        soap.Parameters.Create ( "inputStringArray", sa, "", null,null ) ;        Console.WriteLine("Encoding style: "+soap.EncodingStyle);        Console.WriteLine("Method Name : "+soap.MethodName);        Console.WriteLine("URI : "+soap.URI);        Console.WriteLine(soap.Serialize());        h.SOAPAction = "http://soapinterop.org/" ;        h.Send("http://www.whitemesa.net/interop/std", soap.Serialize());        soap.Parse(h, null);        object[] res = (object[])soap.Parameters.get_Item(0).Value;        Console.WriteLine(res[0]);        Console.WriteLine(res[1]);    }}例子3:
using System;using System.Collections;using PocketSOAP; public class XMListings{    public static void Main()    {        CoEnvelope soap=new CoEnvelope();        HTTPTransport h=new HTTPTransport();        h.SOAPAction="";        soap.MethodName="getAllSOAPServices";        soap.URI="urn:xmethodsServicesManager";        h.Send("http://www.xmethods.net/soap/servlet/rpcrouter", soap.Serialize());                soap.Parse(h, null);        Object[] u = (object[])soap.Parameters.get_Item(0).Value;        foreach (ISOAPNode x in u)        {            Console.WriteLine(x.Nodes.get_ItemByName("name","").Value);            Console.WriteLine(x.Nodes.get_ItemByName("owner","").Value);            Console.WriteLine(x.Nodes.get_ItemByName("serverImplementation","").Value);            Console.WriteLine("-------------------------------");        }        return;    }}


相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。