首页 > 编程 > .NET > 正文

利用PocketSOAP链接webservice(1)---.net

2024-07-10 13:01:46
字体:
来源:转载
供稿:网友

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;    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表