开发者

reading a WSDL file which is in XML format

I am attempting to r开发者_JAVA百科ead a WSDL page, similar to this http://schemas.xmlsoap.org/wsdl/ I am trying to get the operations, data types, input and output information and trying to do this all in C#. Is it like reading an XML file? Is there a tutorial on here, if so can you point me in the right direction.


If you have the URL of the location of a WSDL file, you can navigate to it with a browser, and it will show you the (XML) contents. You should also be able to add it as a (service) reference in a Visual Studio project (right click References -> Add Service Reference).

Once added as a reference to a project, you should be able to use Object Browser to view all the methods, properties, etc. WSDL is pretty old school, so there's a lot of references about it on the Web.


WSDL is indeed an XML format. Here's the official definition for the 1.1 version:

http://www.w3.org/TR/wsdl


call the ReturnOperationsParameters with WSDL path, and you will have everything you required

 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; }
}


You should add a reference to the service by right-clicking your References folder and using "Add Service Reference". Give it the URL to the WSDL and it will create a set of proxy classes that you can call.

Do not use "Add Web Reference". It's obsolete.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜