.NET自动生成的Web服务客户端:如何避免请求架构从w3.org?自动生成、架构、客户端、NET

由网友(情深缘浅)分享简介:我在使用Wsdl.exe工具已经自动生成从WSDL文件一个.NET Web服务客户端。当我第一次实例化生成的类,它开始申请了一堆来自w3.org和其他文件。第一个是 http://www.w3.org/2001/XMLSchema.dtd 的除了不希望造成不必要的流量,以符合w3.org,我需要能够在不向因特网的连接运...

我在使用Wsdl.exe工具已经自动生成从WSDL文件一个.NET Web服务客户端。

当我第一次实例化生成的类,它开始申请了一堆来自w3.org和其他文件。第一个是 http://www.w3.org/2001/XMLSchema.dtd 的

除了不希望造成不必要的流量,以符合w3.org,我需要能够在不向因特网的连接运行应用程序(web的服务是一种内的web服务)。

任何人都知道该如何解决?

如果有帮助,这里是我得到的时候我没有上网的堆栈跟踪:

 的错误,同时打开外部DTDhttp://www.w3.org/2001/XMLSchema.dtd出现了:远程名称不能被解析:WWW。 w3.org'

   在System.Net.HttpWebRequest.GetResponse()
   在System.Xml.XmlDownloadManager.GetNonFileStream(URI URI,ICredentials凭证)
   在System.Xml.XmlDownloadManager.GetStream(URI URI,ICredentials凭证)
   在System.Xml.XmlUrlResolver.GetEntity(URI绝对URI,字符串的作用,类型ofObjectToReturn)
   在System.Xml.XmlTextReaderImpl.OpenStream(URI URI)
   在System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubset(字符串的systenId,字符串publicId)

   在System.Xml.XmlTextReaderImpl.Throw(例外五)
   在System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubset(字符串的systenId,字符串publicId)
   在System.Xml.XmlTextReaderImpl.DtdParserProxy.System.Xml.IDtdParserAdapter.PushExternalSubset(字符串的systenId,字符串publicId)
   在System.Xml.DtdParser.ParseExternalSubset()
   在System.Xml.DtdParser.ParseInDocumentDtd(布尔saveInternalSubset)
   在System.Xml.DtdParser.Parse(布尔saveInternalSubset)
   在System.Xml.XmlTextReaderImpl.DtdParserProxy.Parse(布尔saveInternalSubset)
   在System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
   在System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   在System.Xml.XmlTextReaderImpl.Read()
   在System.Xml.Schema.Parser.StartParsing(XmlReader的读者,字符串目标名称)
   在System.Xml.Schema.Parser.Parse(XmlReader的读者,字符串目标名称)
   在System.Xml.Schema.XmlSchemaSet.ParseSchema(字符串目标名称,XmlReader的读者)
   在System.Xml.Schema.XmlSchemaSet.Add(字符串目标名称,XmlReader的schemaDocument)
   在[...] WebServiceClientType..cctor()在[...]
 
Squid 服务的安装及部署

解决方案

我需要的XmlResolver,所以tamberg's解决方案也不太工作。我通过实现我自己的XmlResolver,从嵌入的资源,而不是下载它们读取所需的模式解决了这个问题。

这个问题没有什么关系自动生成的code,顺便说一句。

该Web服务客户端必须包含这样的事情又实现文件:

 公共部分类[...] WebServiceClientType
  {
    私人静态只读的XmlSchemaSet _schema;

    静态KeyImportFileType()
    {
      _schema =新的XmlSchemaSet();
      _schema.Add(空, XmlResourceResolver.GetXmlReader("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"));
      _schema.Add(空, XmlResourceResolver.GetXmlReader("http://www.w3.org/TR/2002/REC-xmlenc-core-20021210/xenc-schema.xsd"));
      _schema.Compile();
    }
 

和它是这个类的构造函数失败。

I have a .NET web-service client that has been autogenerated from a wsdl-file using the wsdl.exe tool.

When I first instantiate the generated class, it begins to request a bunch of documents from w3.org and others. The first one being http://www.w3.org/2001/XMLSchema.dtd

Besides not wanting to cause unnecessary traffic to w3.org, I need to be able to run the application without a connection to the Internet (the web-service is a "Intra-web-service").

Anyone know the solution?

If it helps, here is the stacktrace I get when I do not have Internet:

"An error has occurred while opening external DTD 'http://www.w3.org/2001/XMLSchema.dtd': The remote name could not be resolved: 'www.w3.org'"

   at System.Net.HttpWebRequest.GetResponse()
   at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials)
   at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
   at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
   at System.Xml.XmlTextReaderImpl.OpenStream(Uri uri)
   at System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubset(String systemId, String publicId)

   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubset(String systemId, String publicId)
   at System.Xml.XmlTextReaderImpl.DtdParserProxy.System.Xml.IDtdParserAdapter.PushExternalSubset(String systemId, String publicId)
   at System.Xml.DtdParser.ParseExternalSubset()
   at System.Xml.DtdParser.ParseInDocumentDtd(Boolean saveInternalSubset)
   at System.Xml.DtdParser.Parse(Boolean saveInternalSubset)
   at System.Xml.XmlTextReaderImpl.DtdParserProxy.Parse(Boolean saveInternalSubset)
   at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.Schema.Parser.StartParsing(XmlReader reader, String targetNamespace)
   at System.Xml.Schema.Parser.Parse(XmlReader reader, String targetNamespace)
   at System.Xml.Schema.XmlSchemaSet.ParseSchema(String targetNamespace, XmlReader reader)
   at System.Xml.Schema.XmlSchemaSet.Add(String targetNamespace, XmlReader schemaDocument)
   at [...]WebServiceClientType..cctor() in [...]

解决方案

I needed the XmlResolver, so tamberg's solution did not quite work. I solved it by implementing my own XmlResolver that read the necessary schemas from embedded resources instead of downloading them.

The problem did not have anything to do with the autogenerated code, by the way.

The web-service-client had another implementation file that contained something like this:

public partial class [...]WebServiceClientType
  {
    private static readonly XmlSchemaSet _schema;

    static KeyImportFileType()
    {
      _schema = new XmlSchemaSet();
      _schema.Add(null, XmlResourceResolver.GetXmlReader("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"));
      _schema.Add(null, XmlResourceResolver.GetXmlReader("http://www.w3.org/TR/2002/REC-xmlenc-core-20021210/xenc-schema.xsd"));
      _schema.Compile();
    }

and it was this class-constructor that failed.

阅读全文

相关推荐

最新文章