我正在尝试让WSDLImporter使用本地WSDL文件并遇到一些问题。远程文件没有问题,因为我使用MetaDataExchangeClient,如下所示:
private MetadataSet GetRemoteMetaData(string wsdlUrl)
{
var address = new Uri(wsdlUrl);
var mexMode = MetadataExchangeClientMode.HttpGet;
var metadataExchangeClient = new MetadataExchangeClient(address, mexMode);
metadataExchangeClient.ResolveMetadataReferences = true;
ServicePointManager.ServerCertificateValidationCallback =
((sender, certificate, chain, sslPolicyErrors) => true);
ICredentials networkCredential = new NetworkCredential("username", "password", "domain");
metadataExchangeClient.HttpCredentials = networkCredential;
return metadataExchangeClient.GetMetadata();
}
但对于本地文件,我尝试使用XmlReader,如下所示:
private MetadataSet GetLocalMetaData(string wsdlPath)
{
return MetadataSet.ReadFrom(XmlReader.Create(wsdlPath));
}
并获得此例外:
<definitions xmlns='http://schemas.xmlsoap.org/wsdl/'> was not expected.
因此它似乎无法处理名称空间/前缀。我知道XmlReader也可以使用XmlReaderSettings类,所以我玩了一下但是找不到任何有用的东西。
任何帮助都将不胜感激。
答案 0 :(得分:0)
public MetadataSet GetRemoteMetadata(string wsdlFilePath)
{
var xmlDoc = XDocument.Load(wsdlFilePath);
var reader = xmlDoc.CreateReader();
var serviceDescription = System.Web.Services.Description.ServiceDescription.Read(reader);
var metadataDocuments = new MetadataSection[] {
MetadataSection.CreateFromServiceDescription(serviceDescription)
};
return new MetadataSet(metadataDocuments);
}