读取XML格式的WSDL文件
问题描述:
我在尝试读取WSDL页面,与此类似http://schemas.xmlsoap.org/wsdl/我试图获取操作,数据类型,输入和输出信息并尝试在C#中完成此操作。它是否像读取XML文件?有没有关于这方面的教程,如果是的话,你能否指出我正确的方向。读取XML格式的WSDL文件
答
如果你有一个WSDL文件的位置的URL,就可以找到它与浏览器,它会告诉你(XML)的内容。您还应该能够将其作为Visual Studio项目中的(服务)引用添加(右键单击引用 - >添加服务引用)。
一旦作为项目的参考添加,您应该可以使用对象浏览器来查看所有的方法,属性等。WSDL很漂亮,所以在Web上有很多关于它的参考。
答
您应该通过右键单击您的参考文件夹并使用“添加服务参考”来添加对该服务的引用。将它提供给WSDL的URL,它将创建一组可以调用的代理类。
请勿使用“添加Web引用”。已经过时了。
答
呼叫ReturnOperationsParameters与WSDL路径,你会拥有一切你需要
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; }
}
-1:为什么你会推荐一个Web引用? –
呼叫良好。习惯的力量,因为我在处理Websphere SOAP调用的.Net 2项目中深深地着迷,并且必须使用Web Reference。编辑我的答案。 –