[英]Inherited properties do not appear in soap sample on asmx file
我有兩個類,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?FeedidID = 520200
即使在微軟確認它是一個錯誤( 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屬性應指向文件在項目中的相對位置。 謝謝你的幫助約翰。
@ Grinn的鏈接已經死了,谷歌搜索CustomWsdlHelpGenerator.aspx沒有變得有用。 但我遇到了這個:
它使用@Grinn引用的方法並使用XSL轉換Wsdl數據以反映繼承。
從鏈接:
獲取已安裝的默認描述生成器DefaultWsdlHelpGenerator.aspx(在我的計算機上,它位於C:\\ WINDOWS \\ Microsoft.NET \\ Framework \\ v2.0.50727 \\ CONFIG中)並將其保存為Web服務的Web目錄中的WsdlHelpGenerator.aspx。 打開你的web.config並把...
<webServices>
<wsdlHelpGenerator href="WsdlHelpGenerator.aspx" />
</webServices>
...在'<system.web>'部分內。
打開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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.