Beispiel #1
0
        // ************************************Constructors**********************************************

        /// <summary>
        /// Constructor creates the web service info from the given url.
        /// </summary>
        /// <param name="wsdlUrl">The WSDL URL.</param>
        /// <param name="user">The user.</param>
        /// <param name="password">The password.</param>
        /// <exception cref="ArgumentNullException">url</exception>
        public WebServiceInfo(Uri wsdlUrl, string user = "", string password = "")
        {
            if (wsdlUrl == null)
            {
                throw new ArgumentNullException("url");
            }

            this.wsdlUrl    = wsdlUrl;
            this.User       = user;
            this.Password   = password;
            this.webMethods = this.GetWebServiceDescription(this.wsdlUrl.AbsoluteUri);
        }
Beispiel #2
0
        /// <summary>
        /// Constructor creates the web service info from the given wsdlUrl.
        /// </summary>
        /// <param name="wsdlUrl">The URL.</param>
        /// <param name="user">The user.</param>
        /// <param name="password">The password.</param>
        /// <exception cref="ArgumentNullException">url</exception>
        public WebServiceInfo(string wsdlUrl, string user = "", string password = "")
        {
            if (wsdlUrl == null)
            {
                throw new ArgumentNullException("url");
            }

            if (!string.IsNullOrEmpty(wsdlUrl))
            {
                this.wsdlUrl    = new Uri(wsdlUrl);
                this.User       = user;
                this.Password   = password;
                this.webMethods = this.GetWebServiceDescription(this.wsdlUrl.AbsoluteUri);
            }
        }
Beispiel #3
0
        // ************************************Functions**********************************************

        /// <summary>
        /// Load the WSDL file from the given url.
        /// Use the ServiceDescription class to walk the wsdl and create the WebServiceInfo
        /// instance.
        /// </summary>
        /// <param name="url">
        private WebMethodInfoCollection GetWebServiceDescription(string url, string portTypeName = "")
        {
            var webMethodInfos = new WebMethodInfoCollection();

            var serviceDescription = this.LoadServiceDescription(url);

            webMethodInfos.AddRange(this.ParseServiceDescription(serviceDescription, portTypeName));

            // When no service url found (in the bindings), try to generate a default
            if (!this.ServiceUrls.Any())
            {
                var fallBackUrl = this.GenerateFallBackServiceUrl(url);
                if (!string.IsNullOrEmpty(fallBackUrl))
                {
                    this.serviceUrls.Add(fallBackUrl);
                }
            }

            return(webMethodInfos);
        }
Beispiel #4
0
        private WebMethodInfoCollection ParseServiceDescription(ServiceDescription serviceDescription, string portTypeName = "")
        {
            var webMethodInfos = new WebMethodInfoCollection();

            foreach (PortType portType in serviceDescription.PortTypes)
            {
                // skip, when a special Porttype is needed
                if (!string.IsNullOrEmpty(portTypeName) && portTypeName != portType.Name)
                {
                    continue;
                }

                foreach (Operation operation in portType.Operations)
                {
                    // get the input parameters
                    var inputMessageName     = operation.Messages.Input != null ? operation.Messages.Input.Message.Name : "";
                    var inputMessagePartName = !string.IsNullOrEmpty(inputMessageName)
                                                                ? serviceDescription.Messages[inputMessageName].Parts.Count > 0
                                                                     ? serviceDescription.Messages[inputMessageName].Parts[0].Element.Name
                                                                     : ""
                                                                : "";

                    var inputParameters = new List <Parameter>();
                    if (!string.IsNullOrEmpty(inputMessagePartName))
                    {
                        inputParameters = this.GetParameters(serviceDescription, inputMessagePartName);
                    }
                    else if (!string.IsNullOrEmpty(inputMessageName))
                    {
                        foreach (MessagePart item in serviceDescription.Messages[inputMessageName].Parts)
                        {
                            inputParameters.Add(new Parameter(item.Name, item.Type.ToString()));
                        }
                    }

                    // get the output parameters
                    var outputMessageName     = operation.Messages.Output != null ? operation.Messages.Output.Message.Name : "";
                    var outputMessagePartName = !string.IsNullOrEmpty(outputMessageName)
                                                                ? serviceDescription.Messages[outputMessageName].Parts.Count > 0
                                                                            ? serviceDescription.Messages[outputMessageName].Parts[0].Element.Name
                                                                            : ""
                                                                : "";

                    var outputParameters = new List <Parameter>();
                    if (!string.IsNullOrEmpty(outputMessagePartName))
                    {
                        outputParameters = this.GetParameters(serviceDescription, outputMessagePartName);
                    }
                    else if (!string.IsNullOrEmpty(outputMessageName))
                    {
                        foreach (MessagePart item in serviceDescription.Messages[outputMessageName].Parts)
                        {
                            outputParameters.Add(new Parameter(item.Name, item.Type.ToString()));
                        }
                    }

                    var action = this.GetAction(serviceDescription, operation.Name);

                    // add new method
                    var webMethodInfo = new WebMethodInfo(operation.Name, inputParameters, outputParameters, "", serviceDescription.TargetNamespace);
                    if (!webMethodInfos.Contains(webMethodInfo.Name))
                    {
                        webMethodInfos.Add(webMethodInfo);
                    }
                }
            }

            // Load and parse includes
            foreach (Import import in serviceDescription.Imports)
            {
                var importedDescription = this.LoadServiceDescription(import.Location);
                webMethodInfos.AddRange(this.ParseServiceDescription(importedDescription, portTypeName));
            }

            // set Soap Action
            foreach (var webMethod in webMethodInfos)
            {
                if (string.IsNullOrEmpty(webMethod.Action))
                {
                    webMethod.Action = this.GetAction(serviceDescription, webMethod.Name);
                }
            }

            // find Service Urls
            foreach (Service service in serviceDescription.Services)
            {
                foreach (Port port in service.Ports)
                {
                    if (port.Extensions[0] is SoapAddressBinding)
                    {
                        var serviceUrl = (port.Extensions[0] as SoapAddressBinding).Location;

                        if (!string.IsNullOrEmpty(serviceUrl))
                        {
                            // Location does not point to the service or endpoint -> generate default
                            if (serviceUrl.EndsWith("/") && !serviceUrl.Contains(port.Service.Name) && !serviceUrl.Contains("."))
                            {
                                serviceUrl += port.Service.Name + ".svc";
                            }

                            this.ServiceUrls.Add(serviceUrl);
                        }
                    }
                }
            }

            return(webMethodInfos);
        }