C# 使用代理根据DTD验证Xml文件。C2.0
我已经看过许多针对DTD验证XML文件的示例,但还没有找到一个允许我使用代理的示例。我有一个cXml文件,其缩写如下,用于显示,我希望对其进行验证:C# 使用代理根据DTD验证Xml文件。C2.0,c#,xml,validation,proxy,dtd,C#,Xml,Validation,Proxy,Dtd,我已经看过许多针对DTD验证XML文件的示例,但还没有找到一个允许我使用代理的示例。我有一个cXml文件,其缩写如下,用于显示,我希望对其进行验证: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.018/InvoiceDetail.dtd"> <cXML payloadID="123456" timestamp="2
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.018/InvoiceDetail.dtd">
<cXML payloadID="123456" timestamp="2009-12-10T10:05:30-06:00">
<!-- content snipped -->
</cXML>
我收到的例外是
System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.
在validator.Read时发生在行上
我知道我可以在本地根据DTD进行验证,但我不想更改xml DOCTYPE,因为这是最终表单所需的内容。此应用程序仅用于诊断目的。有关cXML规范的更多信息,请访问
我感谢任何帮助
谢谢已经有一段时间没有你的问题了,如果有点晚了,很抱歉 以下是被认可的方法: 1-创建您自己的代理程序集:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Configuration;
namespace ProxyAssembly
{
public class MyProxy:IWebProxy
{
#region IWebProxy Members
ICredentials IWebProxy.Credentials
{
get
{
return new NetworkCredential(ConfigurationSettings.AppSettings["googleProxyUser"],ConfigurationSettings.AppSettings["googleProxyPassword"],ConfigurationSettings.AppSettings["googleProxyDomain"]);
}
set { }
}
public Uri GetProxy(Uri destination)
{
return new Uri(ConfigurationSettings.AppSettings["googleProxyUrl"]);
}
public bool IsBypassed(Uri host)
{
return Convert.ToBoolean(ConfigurationSettings.AppSettings["bypassProxy"]);
}
#endregion
}
}
2-将所需的密钥放入web.config:
<add key="googleProxyUrl" value="http://proxy.that.com:8080"/>
<add key="googleProxyUser" value="service"/>
<add key="googleProxyPassword" value="BadDay"/>
<add key="googleProxyDomain" value="corporation"/>
<add key="bypassProxy" value="false"/>
3-将defaultProxy部分放入web.config
<configuration>
<system.net>
<defaultProxy>
<module type="ProxyAssembly.MyProxy, ProxyAssembly"/>
</defaultProxy>
</system.net>
</configuration>
现在,来自应用程序的所有请求都将通过代理。这是所有的请求-即我不认为你可以选择使用这个程序,每一个资源请求将试图通过代理!例如:使用dtd文档、Web服务调用等验证xml
干杯,
兰斯你的问题已经有一段时间没提了,如果有点晚了,我很抱歉 以下是被认可的方法: 1-创建您自己的代理程序集:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Configuration;
namespace ProxyAssembly
{
public class MyProxy:IWebProxy
{
#region IWebProxy Members
ICredentials IWebProxy.Credentials
{
get
{
return new NetworkCredential(ConfigurationSettings.AppSettings["googleProxyUser"],ConfigurationSettings.AppSettings["googleProxyPassword"],ConfigurationSettings.AppSettings["googleProxyDomain"]);
}
set { }
}
public Uri GetProxy(Uri destination)
{
return new Uri(ConfigurationSettings.AppSettings["googleProxyUrl"]);
}
public bool IsBypassed(Uri host)
{
return Convert.ToBoolean(ConfigurationSettings.AppSettings["bypassProxy"]);
}
#endregion
}
}
2-将所需的密钥放入web.config:
<add key="googleProxyUrl" value="http://proxy.that.com:8080"/>
<add key="googleProxyUser" value="service"/>
<add key="googleProxyPassword" value="BadDay"/>
<add key="googleProxyDomain" value="corporation"/>
<add key="bypassProxy" value="false"/>
3-将defaultProxy部分放入web.config
<configuration>
<system.net>
<defaultProxy>
<module type="ProxyAssembly.MyProxy, ProxyAssembly"/>
</defaultProxy>
</system.net>
</configuration>
现在,来自应用程序的所有请求都将通过代理。这是所有的请求-即我不认为你可以选择使用这个程序,每一个资源请求将试图通过代理!例如:使用dtd文档、Web服务调用等验证xml
干杯,
长矛