易截截图软件、单文件、免安装、纯绿色、仅160KB

动态调用WebService(C#)

通常我们在程序中需要调用WebService时,都是通过“添加Web引用”,让VS.NET环境来为我们生成服务代理,然后调用对应的Web服务。这样是使工作简单了,但是却和提供Web服务的URL、方法名、参数绑定在一起了,这是VS.NET自动为我们生成Web服务代理的限制。如果哪一天发布Web服务的URL改变了,则我们需要重新让VS.NET生成代理,并重新编译。在某些情况下,这可能是不能忍受的,我们需要动态调用WebService的能力。比如我们可以把Web服务的URL保存在配置文件中,这样,当服务URL改变时,只需要修改配置文件就可以了。
     说了这么多,实际上我们要实现这样的功能:
public static object InvokeWebService(string url,  string methodname, object[] args)
     其中,url是Web服务的地址,methodname是要调用服务方法名,args是要调用Web服务所需的参数,返回值就是web服务返回的结果了。
     要实现这样的功能,你需要这几个方面的技能:反射、CodeDom、编程使用C#编译器、WebService。在了解这些知识后,就可以容易的实现web服务的动态调用了:
         #region InvokeWebService
        //动态调用web服务
        public static object InvokeWebService(string url, string methodname, object[] args)
         {
            return WebServiceHelper.InvokeWebService(url ,null ,methodname ,args) ;
         }
        public static object InvokeWebService(string url,  string classname, string methodname, object[] args)
         {
            string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling" ;
            if((classname == null) ||(classname == ""))
     &nb


相关文档:

C#序列化与反序列化Xml,利用范型做通用化处理

public class yzzSerialize
{
private yzzSerialize()
{ }
private static yzzCache cache = new yzzCache();
public static T GetfromXml<T>(string xmlpath, T t)
{
using (FileStream fs = new FileStream(xmlpath, FileMode.Open, FileAcces ......

C#中ref参数与out参数的区别

先贴代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ref_and_Out_test
{
    class Program
    {
        static void Main(string[] args)
      & ......

C# 使用PlaySound在移动设备上播放声音

使用 PlaySound 在移动设备上播放声音文件。此代码使用 System.Runtime.InteropServices
调用 Compact Framework 的 CoreDll.DLL 的 PlaySound 方法
关于播放实现:
        //播放标志
        private enum Flags
        {
 &n ......

浅析工厂模式(C#)

我以为,在所有模式中,最简单、最常用的就是工厂模式了(包括抽象工厂)。
工厂模式和抽象模式的区别在于,工厂模式是通过参数(一般叫型别码)来动态生成对象,而抽象工厂必须了解上下文才能调用相应的对象。实例代码如下:
一、工厂模式
public class Factory
{
public static object Create(int type)
{ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号