title: Proxy credentials for programmatically web service proxy class
body: <p>I am having problem to consume a WebService programmatically, using the WSDL under a squid proxy. My application is build in c# .net. I compile an Assembly from the XML, after import the service descripton using this:</p>
  
  <pre><code>// a namespace and compile unit are needed by importer
          CodeNamespace codeNamespace = new CodeNamespace();
          CodeCompileUnit codeUnit = new CodeCompileUnit();
  
          codeUnit.Namespaces.Add(codeNamespace);
  
          ServiceDescriptionImportWarnings importWarnings = descriptionImporter.Import(codeNamespace, codeUnit);
  
          if (importWarnings == 0) // no warnings
          {
              // create a c# compiler
              CodeDomProvider compiler = CodeDomProvider.CreateProvider("CSharp");
  
              // include the assembly references needed to compile
              string[] references = new string[2] { "System.Web.Services.dll", "System.Xml.dll" };
  
              CompilerParameters parameters = new CompilerParameters(references);
  
              // compile into assembly
              CompilerResults results = compiler.CompileAssemblyFromDom(parameters, codeUnit);
  
              foreach (CompilerError oops in results.Errors)
              {
                  // trap these errors and make them available to exception object
                  throw new Exception("Compilation Error Creating Assembly");
              }
  
              // all done....
              return results.CompiledAssembly;
          }
          else
          {
              // warnings issued from importers, something wrong with WSDL
              throw new Exception("Invalid WSDL");
          }
  </code></pre>
  
  <p>The problem is when i call the method Invoke(obj, args). Proxy cut the connection, if i call the WSDL using external address, like <a href="http://My_external_ip/my_webService.asmx" rel="nofollow">http://My_external_ip/my_webService.asmx</a>. If i call using internal address, works fine.</p>
  
  <p>When i add a webReference, manually, i use to do some thing like:</p>
  
  <pre><code>WebService WS = new WebService();
  WS.Proxy = Proxy.credentials;
  </code></pre>
  
  <p>it work, but i couldn't find where to give the proxy credentials when using Assembly.</p>
  
  <p>Thanks guys.</p>