以编程方式 Web 服务代理类的代理凭据

发布于 2024-11-28 04:54:17 字数 1877 浏览 0 评论 0原文

我在使用鱿鱼代理下的 WSDL 以编程方式使用 WebService 时遇到问题。我的应用程序是用 c# .net 构建的。在使用以下命令导入服务描述后,我从 XML 编译程序集:

// 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");
        }

问题是当我调用方法 Invoke(obj, args) 时。如果我使用外部地址调用 WSDL,代理会切断连接,例如 http://My_external_ip/my_webService.asmx。如果我使用内部地址拨打电话,效果很好。

当我手动添加 webReference 时,我通常会执行以下操作:

WebService WS = new WebService();
WS.Proxy = Proxy.credentials;

它可以工作,但在使用 Assembly 时找不到在哪里提供代理凭据。

谢谢你们。

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:

// 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");
        }

The problem is when i call the method Invoke(obj, args). Proxy cut the connection, if i call the WSDL using external address, like http://My_external_ip/my_webService.asmx. If i call using internal address, works fine.

When i add a webReference, manually, i use to do some thing like:

WebService WS = new WebService();
WS.Proxy = Proxy.credentials;

it work, but i couldn't find where to give the proxy credentials when using Assembly.

Thanks guys.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深陷 2024-12-05 04:54:17

@Various,

您可能想编写一些这样的代码

WebService WS = new WebService();
WS.Proxy = wwwproxy("http://someproxy:8080";



  WebProxy wwwproxy(string ptProxyURI) 
{
        var aProxy = New WebProxy;
        aProxy.Credentials = CredentialCache.DefaultCredentials;
        aProxy.BypassProxyOnLocal = True;
        aProxy.Address = New Uri(ptProxyURI);
        Return aProxy;
}

希望它有帮助。

干杯

@Various,

You probebly want to write some code like this

WebService WS = new WebService();
WS.Proxy = wwwproxy("http://someproxy:8080";



  WebProxy wwwproxy(string ptProxyURI) 
{
        var aProxy = New WebProxy;
        aProxy.Credentials = CredentialCache.DefaultCredentials;
        aProxy.BypassProxyOnLocal = True;
        aProxy.Address = New Uri(ptProxyURI);
        Return aProxy;
}

Hope it helps.

Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文