2
如何将自定义节添加到直接在wsdl:definitions下的WSDL?这样的事情: 我已经尝试过使用实现IWsdlExportExtension的自定义属性的东西,但我还没有接近我需要的结果,我不确定这是否是正确的方式来做到这一点。 这是甚至可能的,或者我应该只是将该部分粘贴到文件中并在web.config中指定externalMetadataLocation?WCF自定义WSDL部分
如何将自定义节添加到直接在wsdl:definitions下的WSDL?这样的事情: 我已经尝试过使用实现IWsdlExportExtension的自定义属性的东西,但我还没有接近我需要的结果,我不确定这是否是正确的方式来做到这一点。 这是甚至可能的,或者我应该只是将该部分粘贴到文件中并在web.config中指定externalMetadataLocation?WCF自定义WSDL部分
您的问题的wsdl已从asmx生成。如果你想做同样的事情,你应该使用IVIS库,并用ISService属性装饰你的类。对于WCF你应该下一步:
[CustomAttribute]
public class Service1 : IService1
{
public void DoWork()
{
}
}
public class CustomAttribute:Attribute, System.ServiceModel.Description.IWsdlExportExtension, System.ServiceModel.Description.IWsdlImportExtension, IContractBehavior
{
public void ExportContract(System.ServiceModel.Description.WsdlExporter exporter, System.ServiceModel.Description.WsdlContractConversionContext context)
{
BeforeImport(exporter.GeneratedWsdlDocuments, exporter.GeneratedXmlSchemas, new List<XmlElement>());
}
public void BeforeImport(System.Web.Services.Description.ServiceDescriptionCollection wsdlDocuments, System.Xml.Schema.XmlSchemaSet xmlSchemas, ICollection<XmlElement> policy)
{
//throw new NotImplementedException();
var xdoc = new XmlDocument();
var element = xdoc.CreateElement("ivis","WebServiceInfo", "ivis");
var node = xdoc.CreateNode(XmlNodeType.Element, "Identifier", "ivis");
node.InnerText = "URN:IVIS:100001:ISS-IeM";
element.AppendChild(node);
/// and so on :)
wsdlDocuments[0].Extensions.Add(element);
}
}
所有其他实现接口的方法的主体可以是空的。 这是第一种方法。