.NET自动生成的Web服务客户端:如何避免请求架构从w3.org? [英] .NET autogenerated web-service client: How do I avoid requesting schemas from w3.org?

查看:120
本文介绍了.NET自动生成的Web服务客户端:如何避免请求架构从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()在[...]
 

解决方案

我需要的XmlResolver,所以<一href="http://stackoverflow.com/questions/217841/net-autogenerated-web-service-client-how-do-i-avoid-requesting-schemas-from-w3o#218105">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.

这篇关于.NET自动生成的Web服务客户端:如何避免请求架构从w3.org?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆