Exemple #1
0
        ///

        /// Constructor creates the web service info from the given url.
        ///

        ///
        private WebServiceInfo(Uri url)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            _url        = url;
            _webMethods = GetWebServiceDescription(url);
        }
Exemple #2
0
        ///

        /// Load the WSDL file from the given url.
        /// Use the ServiceDescription class to walk the wsdl and
        ///   create the WebServiceInfo
        /// instance.
        ///

        ///
        private WebMethodInfoCollection GetWebServiceDescription(Uri url)
        {
            UriBuilder uriBuilder = new UriBuilder(url);

            uriBuilder.Query = "WSDL";

            WebMethodInfoCollection webMethodInfos = new WebMethodInfoCollection();

            HttpWebRequest webRequest =
                (HttpWebRequest)WebRequest.Create(uriBuilder.Uri);

            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Method      = "GET";
            webRequest.Accept      = "text/xml";

            ServiceDescription serviceDescription;

            using (System.Net.WebResponse response = webRequest.GetResponse())
                using (System.IO.Stream stream = response.GetResponseStream())
                {
                    serviceDescription = ServiceDescription.Read(stream);
                }
            _serviceName = serviceDescription.Name;
            desc(serviceDescription, url);

            foreach (PortType portType in serviceDescription.PortTypes)
            {
                foreach (Operation operation in portType.Operations)
                {
                    string operationName     = operation.Name;
                    string inputMessageName  = operation.Messages.Input.Message.Name;
                    string outputMessageName = operation.Messages.Output.Message.Name;

                    // get the message part
                    string inputMessagePartName =
                        serviceDescription.Messages[inputMessageName].Parts[0].Element.Name;
                    string outputMessagePartName =
                        serviceDescription.Messages[outputMessageName].Parts[0].Element.Name;

                    // get the parameter name and type
                    Parameter[] inputParameters  = GetParameters(inputMessagePartName);
                    Parameter[] outputParameters = GetParameters(outputMessagePartName);

                    WebMethodInfo webMethodInfo = new WebMethodInfo(
                        operation.Name, inputParameters, outputParameters);
                    webMethodInfos.Add(webMethodInfo);
                }
            }

            return(webMethodInfos);
        }