wsdl解析,提取webservices方法名.有范例
1.以下是一个完整的webservices的wsdl文件. 命名为test.xml
<?xml version= "1.0 " encoding= "utf-8 "?>
<definitions xmlns:http= "http://schemas.xmlsoap.org/wsdl/http/ " xmlns:soap= "http://schemas.xmlsoap.org/wsdl/soap/ " xmlns:s= "http://www.w3.org/2001/XMLSchema " xmlns:s0= "http://tempuri.org/ " xmlns:soapenc= "http://schemas.xmlsoap.org/soap/encoding/ " xmlns:tm= "http://microsoft.com/wsdl/mime/textMatching/ " xmlns:mime= "http://schemas.xmlsoap.org/wsdl/mime/ " targetNamespace= "http://tempuri.org/ " xmlns= "http://schemas.xmlsoap.org/wsdl/ ">
<types>
<s:schema elementFormDefault= "qualified " targetNamespace= "http://tempuri.org/ ">
<s:import namespace= "http://www.w3.org/2001/XMLSchema " />
<s:element name= "GetChildOrgan ">
<s:complexType>
<s:sequence>
<s:element minOccurs= "1 " maxOccurs= "1 " name= "nNodeID " type= "s:int " />
</s:sequence>
</s:complexType>
</s:element>
<s:element name= "GetChildOrganResponse ">
<s:complexType>
<s:sequence>
<s:element minOccurs= "0 " maxOccurs= "1 " name= "GetChildOrganResult ">
<s:complexType>
<s:sequence>
<s:element ref= "s:schema " />
<s:any />
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</types>
<message name= "GetChildOrganSoapIn ">
<part name= "parameters " element= "s0:GetChildOrgan " />
</message>
<message name= "GetChildOrganSoapOut ">
<part name= "parameters " element= "s0:GetChildOrganResponse " />
</message>
<portType name= "OrganInfoServiceSoap ">
<operation name= "GetChildOrgan ">
<documentation> 提供根据机构编号检索当前机构及其以下机构信息集(正在运行中的机构) </documentation>
<input message= "s0:GetChildOrganSoapIn " />
<output message= "s0:GetChildOrganSoapOut " />
</operation>
</portType>
<binding name= "OrganInfoServiceSoap " type= "s0:OrganInfoServiceSoap ">
<soap:binding transport= "http://schemas.xmlsoap.org/soap/http " style= "document " />
<operation name= "GetChildOrgan ">
<soap:operation soapAction= "http://tempuri.org/GetChildOrgan " style= "document " />
<input>
<soap:body use= "literal " />
</input>
<output>
<soap:body use= "literal " />
</output>
</operation>
</binding>
<service name= "OrganInfoService ">
<port name= "OrganInfoServiceSoap " binding= "s0:OrganInfoServiceSoap ">
<soap:address location= "http://hr.hnair.net/IHRSysWebService/OrganInfoService.asmx " />
</port>
</service>
</definitions>
2.我需要提取出portType 下operation 中的name 即GetChildOrgan.请教该怎么提取.
3.以下是我写的一段代码.
using System.xml;
XmlDocument doc = new XmlDocument();
doc.Load(@ "c:/test.xml ");
XmlNodeList nodes = doc.SelectNodes( "definitions/portType/operation ");
foreach (XmlNode node in nodes)
{
XmlElement xe = (XmlElement)node;
Response.Write(xe.GetAttribute( "name ") + " <br> ");
}
请教那里有错.本人新手.谢谢勿嫌分少.
[解决办法]
是标准xml,包含名称空间的定义,