继承的属性不会出现在 asmx 文件的肥皂示例中

发布于 2024-08-13 14:53:35 字数 1098 浏览 1 评论 0原文

我有两个类,WebServiceRequest 和 OrderRequest。每个类都有属性。 OrderRequest 继承自 WebServiceRequest - 就像这样:

    public class WebServiceRequest
    {
        private string mAuthenticationToken;

        public string AuthenticationToken
        {
            get { return mAuthenticationToken; }
            set { mAuthenticationToken = value; }
        }
        ...
}

public class OrderRequest : WebServiceRequest
{

    private string mVendorId;
    public string VendorId
    {
        get { return mVendorId; }
        set { mVendorId = value; }
    }
    ...
}

OrderRequest 通过 WebMethod 公开。当查看公开 OrderRequest 的 ASMX 文件的 WSDL(即 MyWebService.asmx?WSDL)时,这两个属性都是可见的 - 正如它们应该的那样。但是,当您查看公开 OrderRequest 的 Web 方法的 SOAP 示例时,只有 VendorId 属性可见,而继承的 AuthenticationToken 属性不可见。这是怎么回事?

注意:我已将此问题作为 MS Connect 上的错误发布:https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=520200

I have two classes, WebServiceRequest and OrderRequest. Each class has properties. OrderRequest inherits from WebServiceRequest - like so:

    public class WebServiceRequest
    {
        private string mAuthenticationToken;

        public string AuthenticationToken
        {
            get { return mAuthenticationToken; }
            set { mAuthenticationToken = value; }
        }
        ...
}

public class OrderRequest : WebServiceRequest
{

    private string mVendorId;
    public string VendorId
    {
        get { return mVendorId; }
        set { mVendorId = value; }
    }
    ...
}

OrderRequest is exposed via a WebMethod. When viewing the WSDL of the ASMX file that exposes OrderRequest (i.e. MyWebService.asmx?WSDL), both properties are visible - as they should be. However, when you view the SOAP Sample for the Web Method that exposes OrderRequest, only the VendorId property is visible, and not the inherited AuthenticationToken property. What's the deal?

Note: I've posted this issue as a bug on MS Connect: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=520200

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

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

发布评论

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

评论(3

没︽人懂的悲伤 2024-08-20 14:53:35

即使微软确认它是一个错误(https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=520200),我已经放弃并将约翰的答案标记为已接受。解决方案如下:

http://code.msdn.microsoft。 com/WsdlHelpGenerator/Release/ProjectReleases.aspx?ReleaseId=412

转到此处,下载文件,然后在 Web.config 文件的 system.web 部分下添加以下行:

<webServices>
 <wsdlHelpGenerator href="CustomWsdlHelpGenerator.aspx"/>
</webServices>

href 属性应指向相对的文件在项目中的位置。谢谢你的帮助约翰。

I managed to stumble back-asswords into the solution for my problem, even after Microsoft confirmed it as a bug (https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=520200) and I had given up and marked John's answer as accepted. Here's the solution:

http://code.msdn.microsoft.com/WsdlHelpGenerator/Release/ProjectReleases.aspx?ReleaseId=412

Go there, download the file, then add the following line under the system.web section of your Web.config file:

<webServices>
 <wsdlHelpGenerator href="CustomWsdlHelpGenerator.aspx"/>
</webServices>

The href property should point to the relative location of your file within your project. Thanks for your help John.

感受沵的脚步 2024-08-20 14:53:35

不必使用[XmlIninclude]

由于帮助页面的外观(当您点击 .asmx URL 时在浏览器中看到的内容),您似乎认为这是一个问题。不要那样做。相反,查看实际返回的内容。


更新:
OP 创建了一个 此问题的连接错误。此错误已于 2010 年 1 月 11 日以“无法修复”的形式得到解决:

我们已经确认继承的
属性不显示在 SOAP 中
浏览器上的示例就是
确实是产品中的一个错误。

此时,该区域位于
维护模式,无主动工作
已计划。

It should not be necessary to use [XmlInclude].

You seem to be judging this to be a problem because of the appearance of the help page (what you get in the browser when you hit the .asmx URL). Don't do that. Instead, look to see what is actually returned.


Update:
The OP created a Connect bug for this issue. This bug was resolved as "won't fix" on 1/11/2010:

We have confirmed that the inherited
properties do not show up in SOAP
Sample on the browser and that is
indeed a bug in the product.

At this point, this area is in
maintainance mode, and no active work
is planned.

水中月 2024-08-20 14:53:35

@Grinn 的链接已失效,谷歌搜索 CustomWsdlHelpGenerator.aspx 没有找到任何有用的内容。但我遇到了这个:

改进 ASP .NET Webservice Help Generator

它使用 @Grinn 引用的方法,并使用 XSL 转换 Wsdl 数据以反映继承。

从链接:

获取已安装的默认描述生成器 DefaultWsdlHelpGenerator.aspx(在我的计算机上,它位于 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG 中)并将其另存为 WsdlHelpGenerator.aspx 到您的 Web 目录中网络服务。打开你的 web.config 并将...

<webServices>
  <wsdlHelpGenerator href="WsdlHelpGenerator.aspx" />
</webServices>

...放入“”中部分。

打开 WsdlHelpGenerator.aspx 并将这两个方法添加到 Page_Load 方法的正下方:

protected override void OnPreLoad(EventArgs e) {
   base.OnPreLoad(e);

   // transform any service description stored within HttpContext
   // cf. Page_Load: try "wsdlsWithPost" first and fall back to "wsdls"
   string key = Context.Items["wsdlsWithPost"] != null ?
               "wsdlsWithPost" : "wsdls";

   serviceDescriptions = (ServiceDescriptionCollection)Context.Items[key];
   TransformServiceDescriptions(ref serviceDescriptions);
   Context.Items[key] = serviceDescriptions;
 }

void TransformServiceDescriptions(ref ServiceDescriptionCollection descriptions) {

   // modify each description by an XSLT processor
   ServiceDescriptionCollection transformed = new ServiceDescriptionCollection();
   System.Xml.Xsl.XslCompiledTransform xslt =
       new System.Xml.Xsl.XslCompiledTransform();
   xslt.Load(Server.MapPath("WsdlHelp.xsl"));

   foreach (ServiceDescription desc in descriptions)
   {
     // load original WSDL data
     MemoryStream ms1 = new MemoryStream(), ms2 = new MemoryStream();
     desc.Write(ms1);

     // process WSDL data using WsdlHelp.xsl
     ms1.Position = 0;
     xslt.Transform(new System.Xml.XPath.XPathDocument(ms1), null, ms2);

     // replace current WSDL data with the transformed stream
     ms2.Position = 0;
     transformed.Add(ServiceDescription.Read(ms2));

     ms1.Dispose();
     ms2.Dispose();
   }
   descriptions = transformed;
}

最后,为了使此代码正常工作,请将转换文件 WsdlHelp.xsl 放入 Web 服务的 Web 目录中。它可能如下所示:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:s="http://www.w3.org/2001/XMLSchema">
  <xsl:output
    method="xml"
    indent="no"
    encoding="utf-8"
    omit-xml-declaration="no"
  />
  <!-- recursively dissolve any schema extension elements to the base structure -->

  <xsl:template match="/" xml:space="default">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="*" priority="0.5" xml:space="default">
    <xsl:copy>
      <xsl:copy-of select="attribute::*" />
      <xsl:choose>
        <xsl:when test="child::*" />
        <xsl:otherwise>
          <xsl:value-of select="." />
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates select="child::*" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="s:complexType" priority="1.0">
    <xsl:element name="s:complexType" namespace="http://www.w3.org/2001/XMLSchema">
      <xsl:copy-of select="attribute::*" />
      <xsl:element name="s:sequence">
        <xsl:copy-of select=".//s:sequence/*" />
        <xsl:if test="./s:complexContent/s:extension">
          <xsl:comment> schema extension expanded: <xsl:value-of
            select="./s:complexContent/s:extension/@base"/> </xsl:comment>
          <xsl:call-template name="fetch-sequence">
            <xsl:with-param name="typename"
              select="substring-after(./s:complexContent/s:extension/@base,':')" />
          </xsl:call-template>
        </xsl:if>
      </xsl:element>
    </xsl:element>
  </xsl:template>

  <xsl:template name="fetch-sequence">
    <xsl:param name="typename" />
    <xsl:copy-of select="//s:complexType[@name = $typename]//s:sequence/*" />
    <xsl:if test="//s:complexType[@name = $typename]/s:complexContent/s:extension">
      <xsl:call-template name="fetch-sequence">
        <xsl:with-param name="typename"
          select="substring-after(//s:complexType[@name = $typename]
                /s:complexContent/s:extension/@base,':')" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

@Grinn's link is dead and googling CustomWsdlHelpGenerator.aspx didn't turn anything useful up. But I came across this:

Improving the ASP.NET Webservice Help Generator

It uses the approach @Grinn refers to and uses an XSL to transform the Wsdl data to reflect inheritance.

From the link:

Get the installed default description generator DefaultWsdlHelpGenerator.aspx (on my computer, it's in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG) and save it as WsdlHelpGenerator.aspx in the web directory of your webservice. Open your web.config and put...

<webServices>
  <wsdlHelpGenerator href="WsdlHelpGenerator.aspx" />
</webServices>

... inside the '<system.web>' section.

Open WsdlHelpGenerator.aspx and add these two methods directly below the Page_Load method:

protected override void OnPreLoad(EventArgs e) {
   base.OnPreLoad(e);

   // transform any service description stored within HttpContext
   // cf. Page_Load: try "wsdlsWithPost" first and fall back to "wsdls"
   string key = Context.Items["wsdlsWithPost"] != null ?
               "wsdlsWithPost" : "wsdls";

   serviceDescriptions = (ServiceDescriptionCollection)Context.Items[key];
   TransformServiceDescriptions(ref serviceDescriptions);
   Context.Items[key] = serviceDescriptions;
 }

void TransformServiceDescriptions(ref ServiceDescriptionCollection descriptions) {

   // modify each description by an XSLT processor
   ServiceDescriptionCollection transformed = new ServiceDescriptionCollection();
   System.Xml.Xsl.XslCompiledTransform xslt =
       new System.Xml.Xsl.XslCompiledTransform();
   xslt.Load(Server.MapPath("WsdlHelp.xsl"));

   foreach (ServiceDescription desc in descriptions)
   {
     // load original WSDL data
     MemoryStream ms1 = new MemoryStream(), ms2 = new MemoryStream();
     desc.Write(ms1);

     // process WSDL data using WsdlHelp.xsl
     ms1.Position = 0;
     xslt.Transform(new System.Xml.XPath.XPathDocument(ms1), null, ms2);

     // replace current WSDL data with the transformed stream
     ms2.Position = 0;
     transformed.Add(ServiceDescription.Read(ms2));

     ms1.Dispose();
     ms2.Dispose();
   }
   descriptions = transformed;
}

Finally, to get this code working, put the transformation file WsdlHelp.xsl into the web directory of your webservice. It may look as follows:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:s="http://www.w3.org/2001/XMLSchema">
  <xsl:output
    method="xml"
    indent="no"
    encoding="utf-8"
    omit-xml-declaration="no"
  />
  <!-- recursively dissolve any schema extension elements to the base structure -->

  <xsl:template match="/" xml:space="default">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="*" priority="0.5" xml:space="default">
    <xsl:copy>
      <xsl:copy-of select="attribute::*" />
      <xsl:choose>
        <xsl:when test="child::*" />
        <xsl:otherwise>
          <xsl:value-of select="." />
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates select="child::*" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="s:complexType" priority="1.0">
    <xsl:element name="s:complexType" namespace="http://www.w3.org/2001/XMLSchema">
      <xsl:copy-of select="attribute::*" />
      <xsl:element name="s:sequence">
        <xsl:copy-of select=".//s:sequence/*" />
        <xsl:if test="./s:complexContent/s:extension">
          <xsl:comment> schema extension expanded: <xsl:value-of
            select="./s:complexContent/s:extension/@base"/> </xsl:comment>
          <xsl:call-template name="fetch-sequence">
            <xsl:with-param name="typename"
              select="substring-after(./s:complexContent/s:extension/@base,':')" />
          </xsl:call-template>
        </xsl:if>
      </xsl:element>
    </xsl:element>
  </xsl:template>

  <xsl:template name="fetch-sequence">
    <xsl:param name="typename" />
    <xsl:copy-of select="//s:complexType[@name = $typename]//s:sequence/*" />
    <xsl:if test="//s:complexType[@name = $typename]/s:complexContent/s:extension">
      <xsl:call-template name="fetch-sequence">
        <xsl:with-param name="typename"
          select="substring-after(//s:complexType[@name = $typename]
                /s:complexContent/s:extension/@base,':')" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

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