读取XML格式的WSDL文件
本文关键字:WSDL 文件 格式 XML 读取 | 更新日期: 2023-09-27 18:11:25
我试图读取WSDL页面,类似于此http://schemas.xmlsoap.org/wsdl/我试图获得操作,数据类型,输入和输出信息,并试图在c#中完成这一切。是否类似于读取XML文件?这里有教程吗,如果有,你能给我指出正确的方向吗?
如果您有WSDL文件位置的URL,您可以使用浏览器导航到它,它将显示(XML)内容。您还应该能够将其添加为Visual Studio项目中的(服务)引用(右键单击References -> add service reference)。
一旦作为一个项目的引用添加,你应该能够使用对象浏览器来查看所有的方法,属性等。WSDL是相当老派的,因此在Web上有很多关于它的参考资料。
WSDL确实是一种XML格式。下面是1.1版本的官方定义:
http://www.w3.org/TR/wsdl使用WSDL路径调用 returnperationparameters ,您将获得所需的一切
public static void ReturnOperationsParameters(string fileName)
{
var reader = new XmlTextReader(fileName);
var serviceDescription = ServiceDescription.Read(reader);
BindingCollection bindColl = serviceDescription.Bindings;
PortTypeCollection portTypColl = serviceDescription.PortTypes;
MessageCollection msgColl = serviceDescription.Messages;
Types typs = serviceDescription.Types;
foreach (Service service in serviceDescription.Services)
{
String webServiceNmae = service.Name.ToString();
foreach (Port port in service.Ports)
{
string portName = port.Name;
string binding = port.Binding.Name;
System.Web.Services.Description.Binding bind = bindColl[binding];
PortType portTyp = portTypColl[bind.Type.Name];
foreach (Operation op in portTyp.Operations)
{
var operatioList = new SoapData();
// _soapdata = new SoapData();
OperationMessageCollection opMsgColl = op.Messages;
OperationInput opInput = opMsgColl.Input;
string inputMsg = opInput.Message.Name;
Message msgInput = msgColl[inputMsg];
MessagePart part = msgInput.Parts[0];
operatioList.OperationName = op.Name;
operatioList.NameSpace = part.Element.Namespace;
TreeItemSource.Add(operatioList);
}
}
}
}
}
public class SoapData
{
public int Id { get; set; }
public string RequestXml { get; set; }
public string ResponseXml { get; set; }
public string NameSpace { get; set; }
public string OperationName { get; set; }
}
您应该通过右键单击References文件夹并使用" add service reference "向服务添加引用。为WSDL提供URL,它将创建一组您可以调用的代理类。
不要使用"Add Web Reference"。这是过时了。