如题:
在BLL层调用的webService、服务引用的配置怎么移到web层,做到只配置就行了呢?我看到BLL层的Settings.settings里面就可配置webService的地址,app.config里面配置服务引用的地址,这些怎么移到web.config或者Bin里面的文件里面配置呢?

解决方案 »

  1.   

    private object InvokeWebservice(string url, string @namespace, string classname, string methodname, object[] args) 
      { 
       try 
       { 
        System.Net.WebClient wc = new System.Net.WebClient(); 
        System.IO.Stream stream = wc.OpenRead(url+"?WSDL"); 
        System.Web.Services.Description.ServiceDescription sd = System.Web.Services.Description.ServiceDescription.Read(stream); 
        System.Web.Services.Description.ServiceDescriptionImporter sdi = new System.Web.Services.Description.ServiceDescriptionImporter(); 
        sdi.AddServiceDescription(sd,"",""); 
        System.CodeDom.CodeNamespace cn = new System.CodeDom.CodeNamespace(@namespace); 
        System.CodeDom.CodeCompileUnit ccu = new System.CodeDom.CodeCompileUnit(); 
        ccu.Namespaces.Add(cn); 
        sdi.Import(cn,ccu);     Microsoft.CSharp.CSharpCodeProvider csc = new Microsoft.CSharp.CSharpCodeProvider(); 
        System.CodeDom.Compiler.ICodeCompiler icc = csc.CreateCompiler();     System.CodeDom.Compiler.CompilerParameters cplist = new System.CodeDom.Compiler.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");     System.CodeDom.Compiler.CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu); 
        if(true == cr.Errors.HasErrors) 
        { 
         System.Text.StringBuilder sb = new System.Text.StringBuilder(); 
         foreach(System.CodeDom.Compiler.CompilerError ce in cr.Errors) 
         { 
          sb.Append(ce.ToString()); 
          sb.Append(System.Environment.NewLine); 
         } 
         throw new Exception(sb.ToString()); 
        } 
        System.Reflection.Assembly assembly = cr.CompiledAssembly; 
        Type t = assembly.GetType(@namespace+"."+classname,true,true); 
        object obj = Activator.CreateInstance(t); 
        System.Reflection.MethodInfo mi = t.GetMethod(methodname); 
        return mi.Invoke(obj,args); 
       } 
       catch(Exception ex) 
       { 
        throw new Exception(ex.InnerException.Message,new Exception(ex.InnerException.StackTrace)); 
       } 
      } 
      

  2.   

    都配置在WEB.CONFIG里,相对于其它层WEB层是宿主程序,是WEB层调用其它层,所以直接配置在WEB。CONFIG就行了。
      

  3.   


    是在BLL层添加服务引用,WS引用,怎么把配置移动web层呀?不可能把自动生成的文件移到Web层吧,这样都运行不了啦
      

  4.   

    直接修改web.config文件
    vs添加web service引用的时候,会在web.config中的appSetting里面添加一个web service的url地址。
    大概类似如下
    <add key="localhost.WebService" value="http://localhost:5326/WebSite3/WebService.asmx"/>
    添加一个自定义的类,继承vs生成的web service代理类,在这个自定义类里面,可以添加带url的构造函数public class CustomedWebService:VSGeneratedWebService
    {
      public CustomedWebService(string url)
      {
      }
      

  5.   

    1、先部署一个webservice在iis上。  
    部署成功后在浏览器中生成wsdl文件就是xml文件(生成方法:webservice地址后加上?wsdl,如localhost/xx.asmx?wsdl)  
    拿到wsdl文件后在vs命令prompt下执行:wsdl [你生成的wsdl文件],这样会生成一个cs文件。  
    然后把类文件添加到项目里,在程序中调用该cs文件中的方法。 
    2、4楼提供的方法,在项目里添加webservice引用