liuwenjun830

  博客园 :: 首页 :: 联系 :: 订阅 订阅 :: 管理
  8 Posts :: 0 Stories :: 22 Comments :: 0 Trackbacks

公告

昵称:IDon'tKnow
园龄:5年9个月
粉丝:8
关注:0

搜索

 
 

常用链接

最新评论

阅读排行榜

评论排行榜

推荐排行榜

2010年11月5日 #

 
代码
namespace DynamicCallWebService
{
    
public class WebServiceCaller
    {
        
public static object InvokeWebService(string url, string methodName, object[] args)
        {
            
return InvokeWebService(url, null, methodName, args);
        }
        
public static object InvokeWebService(string url, string className, string methodName, object[] args)
        {
            
string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
            
if (string.IsNullOrEmpty(className))
            {
                className 
= GetWsClassName(url);
            }
            
try
            {
                
//Get WSDL
                string wsdlUrl = url + "?WSDL";
                WebClient webClient 
= new WebClient();
                Stream stream 
= webClient.OpenRead(wsdlUrl);
                ServiceDescription sd 
= ServiceDescription.Read(stream);
                
if (!string.IsNullOrEmpty(sd.Name) && sd.Name != className)
                    className 
= sd.Name;
                ServiceDescriptionImporter sdi 
= new ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, 
"""");

                
                
// Add any child namespaces First
                foreach (Import schemaImport in sd.Imports)
                {
                    Uri baseUri 
= new Uri(wsdlUrl);
                    
string schemaLocation = schemaImport.Location;
                    
if (schemaLocation == null)
                        
continue;
                    Uri schemaUri 
= new Uri(baseUri, schemaLocation);

                    
using (Stream schemaStream = webClient.OpenRead(schemaUri))
                    {
                        
try
                        {
                            ServiceDescription sdImport 
= ServiceDescription.Read(schemaStream, true);
                            sdImport.Namespaces.Add(
"wsdl", schemaImport.Namespace);
                            sdi.AddServiceDescription(sdImport, 
nullnull);
                        }
                        
catch { }  // ignore schema import errors
                    }
                }

                
// Download and inject any imported schemas (ie. WCF generated WSDL)            
                foreach (XmlSchema wsdlSchema in sd.Types.Schemas)
                {
                    
// Loop through all detected imports in the main schema
                    foreach (XmlSchemaObject externalSchema in wsdlSchema.Includes)
                    {
                        
// Read each external schema into a schema object and add to importer
                        if (externalSchema is XmlSchemaImport)
                        {
                            Uri baseUri 
= new Uri(wsdlUrl);
                            
string exSchemaLocation = ((XmlSchemaExternal)externalSchema).SchemaLocation;
                            
if (string.IsNullOrEmpty(exSchemaLocation))
                                
continue;

                            Uri schemaUri 
= new Uri(baseUri, exSchemaLocation);

                            
using (Stream schemaStream = webClient.OpenRead(schemaUri))
                            {
                                
try
                                {
                                    System.Xml.Schema.XmlSchema schema 
= XmlSchema.Read(schemaStream, null);
                                    sdi.Schemas.Add(schema);
                                }
                                
catch { }  // ignore schema import errors                                                        
                            }
                        }
                    }
                }

                CodeNamespace cn 
= new CodeNamespace(@namespace);
                
//Create Client proxy class
                CodeCompileUnit ccu = new CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);
                CSharpCodeProvider csc 
= new CSharpCodeProvider();
                ICodeCompiler icc 
= csc.CreateCompiler();
                
//Set complier parameters
                CompilerParameters cplist = new CompilerParameters();
                cplist.GenerateExecutable 
= false;
                cplist.GenerateInMemory 
= true;
                cplist.ReferencedAssemblies.Add(
"System.dll");
                cplist.ReferencedAssemblies.Add(
"System.XML.dll");
                cplist.ReferencedAssemblies.Add(
"System.Web.Services.dll");
                cplist.ReferencedAssemblies.Add(
"System.Data.dll");
                
//complie proxy class
                CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
                
if (true == cr.Errors.HasErrors)
                {
                    StringBuilder sb 
= new StringBuilder();
                    
foreach (CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(Environment.NewLine);
                    }
                    
throw new Exception(sb.ToString());
                }
                
//Generate proxy instance and invoke mehtod
                Assembly assembly = cr.CompiledAssembly;
                Type t 
= assembly.GetType(@namespace + "." + className, truetrue);
                
object obj = Activator.CreateInstance(t);
                MethodInfo method 
= t.GetMethod(methodName);
                
return method.Invoke(obj, args);
            }
            
catch (Exception ex)
            {
                
throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
            }
        }

        
public static string GetWsClassName(string wsUrl)
        {
            
string[] parts = wsUrl.Split('/');
            
string[] pps = parts[parts.Length - 1].Split('.');
            
return pps[0];
        }
    }
}


posted @ 2010-11-05 10:46 IDon'tKnow 阅读(372) 评论(0) 编辑

2006年12月8日 #

摘要: 1<!--2/**//*****************************************************************************3日期资料4*****************************************************************************/56varlunarInfo=newArray(7...阅读全文
posted @ 2006-12-08 09:07 IDon'tKnow 阅读(1509) 评论(2) 编辑

2006年7月28日 #

一,哈希表(Hashtable)简述

  在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似keyvalue的键值对,其中key通常可用来快速查找,同时key是区分大小写;value用于存储对应于key的值。Hashtable中keyvalue键值对均为object类型,所以Hashtable可以支持任何类型的keyvalue键值对.

二,哈希表的简单操作

 在哈希表中添加一个keyvalue键值对:HashtableObject.Add(key,value);
 在哈希表中去除某个keyvalue键值对:HashtableObject.Remove(key);
 从哈希表中移除所有元素:           HashtableObject.Clear();
 判断哈希表是否包含特定键key:      HashtableObject.Contains(key);
 下面控制台程序将包含以上所有操作:
using System;
using System.Collections; file使用Hashtable时,必须引入这个命名空间
class hashtable
{
  public static void Main()
  {
  Hashtable ht=new Hashtable(); file创建一个Hashtable实例
  ht.Add(E,e);添加keyvalue键值对
  ht.Add(A,a);
  ht.Add(C,c);
  ht.Add(B,b);

  string s=(string)ht[A];
  if(ht.Contains(E)) file判断哈希表是否包含特定键,其返回值为true或false
    Console.WriteLine(the E keyexist);
  ht.Remove(C);移除一个keyvalue键值对
  Console.WriteLine(ht[A]);此处输出a
  ht.Clear();移除所有元素
  Console.WriteLine(ht[A]); file此处将不会有任何输出
  }
}

三,遍历哈希表

 遍历哈希表需要用到DictionaryEntry Object,代码如下:
 for(DictionaryEntry de in ht) fileht为一个Hashtable实例
 {
   Console.WriteLine(de.Key);de.Key对应于keyvalue键值对key
   Console.WriteLine(de.Value);de.Key对应于keyvalue键值对value
 }

四,对哈希表进行排序

  对哈希表进行排序在这里的定义是对keyvalue键值对中的key按一定规则重新排列,但是实际上这个定义是不能实现的,因为我们无法直接在Hashtable进行对key进行重新排列,如果需要Hashtable提供某种规则的输出,可以采用一种变通的做法:
 ArrayList akeys=new ArrayList(ht.Keys); file别忘了导入System.Collections
 akeys.Sort(); file按字母顺序进行排序
 for(string skey in akeys)
 {
   Console.Write(skey + );
   Console.WriteLine(ht[skey]);排序后输出
 }

posted @ 2006-07-28 15:24 IDon'tKnow 阅读(64924) 评论(15) 编辑

2006年7月14日 #

正则表达式在C#中的用法:

MatchCollection Matches =Regex.Matches(string text,string pattern,RegexOptions RegexOption)
三个参数:string text所要查找的字符
                   string pattern所要匹配的字符串
                   RegexOptions ResgexOption 所要用的规则

例如:
string Pattern =@"\bn";
表示要查找以n开头的字
string pattern =@"ion\b"
表示查找以ion结尾的字
string pattern =@"\ba\S*ion\b";
表示以a和ion中间的内容可以是任意长度的任意字符,只要这些字符不是空白即可。

                                                                常用的参数表:
符号                              含义                                                     示例               匹配的示例
^                                输入文本的开头                                       ^B                  B,但只能是文本中的第一个字符
$                                输入文本的结尾                                       X$                  X,但只能是文本中的最后一个字符
.                                除了换行符(\n)以外的所有单个字符        i.ation           isation、ization
*                               可以重复0次或多次的前导字符               ra*t              rt、rat、raat和raaat等
+                               可以重复1次或多次的前导字符             ra+t                rat、raat和raaat等(但不能是rt)
\s                              任何空白字符                                            \sa        [space]a、\ta、\na(\t和\n与C#的\t和\n含义相同
\S                             任何不是空白的字符                                \SF                 aF、rF、cF、但不能是\tf
\b                              字边界                                                        ion\b              以ion结尾的任何字
\B                            不是字边界的位置                                    \BX\B              字中间的任何X
posted @ 2006-07-14 16:32 IDon'tKnow 阅读(428) 评论(0) 编辑

2006年5月26日 #

摘要: OracleTransactionmyTrans;conn.Open();myTrans=conn.BeginTransaction(IsolationLevel.ReadCommitted);comm.Transaction=myTrans;comm.CommandText="insertintoTagInfo(TagID,AutoSubSysID,TagCode,TagName,TagType...阅读全文
posted @ 2006-05-26 23:41 IDon'tKnow 阅读(2636) 评论(0) 编辑

2006年5月8日 #

摘要: 由于以前对DataGrid的了解相当初浅,只能用来显示数据今天做了一下对DataGrid的深入学习通过在网上搜索相关资料,总算能让例子达到自己的初步要求也开始明白为什么别人说学习是一个循序渐进的过程主要用到的一些代码:usingSystem;usingSystem.Drawing;usingSystem.Collections;usingSystem.ComponentModel;usingSys...阅读全文
posted @ 2006-05-08 17:30 IDon'tKnow 阅读(431) 评论(2) 编辑

2006年5月6日 #

摘要: 最近一段时间一直在围绕树形控件在做东西在最开始的一段时间里由于开始所用的数据类型是用数据组实现的造成在后期的树形控件的节点的添加困难最终还是取消了用数组来实现,而用了DataSet主要相关代码:privatevoidtreeView1_AfterSelect(objectsender,System.Windows.Forms.TreeViewEventArgse){try{//节点为根节点if(t...阅读全文
posted @ 2006-05-06 14:18 IDon'tKnow 阅读(1072) 评论(1) 编辑

2006年4月19日 #

摘要: 我是今年才毕业的应届生,找了一家公司,主要从事.net开发。公司让我从事Remoting开发,最近几天看了wayfarer的一些文章,觉得很好,自己也试着做了一个小程序,不知道为什么达不到预期的效果。现在把程序发上来,希望大家能为我解决问题。远程类:usingSystem;usingSystem.Runtime.Remoting;namespaceDistribution_Framework{//...阅读全文
posted @ 2006-04-19 08:34 IDon'tKnow 阅读(829) 评论(2) 编辑