"The provided URI scheme 'http' is invalid; expected 'https'.\r\nParameter name: via" error while connecting to list in site collections through lists.asmx webservice RRS feed

  • Question

  • Hi,

    I am getting error : The provided URI scheme 'http' is invalid; expected 'https'.\r\nParameter name: via

    It does not cause an issue if list is on webapplication level(https://), it causes an issue's for site collection leevel(http://).

    Is it something we need to add site collection into secured port as (https://)..something???

    while trying to connect to list using below code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Security.Principal;
    using System.ServiceModel;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Xml;
    using System.Xml.Linq;
    using FWCHandler.Interfaces;
    using FWCHandler.ListServiceReference;
    using FWCHandler.Utilities;
    using FWCHandler.ListWebServiceReference;
    namespace FWCHandler
        public class FWCHandlerClient
            protected readonly string _Domain = string.Empty;
            protected readonly string _Password = string.Empty;
            protected readonly string _UserName = string.Empty;
            private IFWCHandler _Item;
            private string _ItemCount = "0";
            private string _ListName = string.Empty;
            protected string _ProjectsURL = string.Empty;
            private string _SiteUrl = string.Empty;
            private string _listId = string.Empty;
            ListWebServiceReference.Lists  list1 = new ListWebServiceReference.Lists();
            private ListsSoapClient _lspc;
            private XmlDocument _xmlDoc;
            public FWCHandlerClient(string projectsUrl, string listName, string userName, string password, string domain)
                _ProjectsURL = projectsUrl;
                _ListName = listName;
                _UserName = userName;
                _Password = password;
                _Domain = domain;
                _lspc = CreateProxy(_ProjectsURL + "/_vti_bin/lists.asmx");
            private ListsSoapClient CreateProxy(string url)
                var Binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
                Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
                var Endpoint = new EndpointAddress(url);
                var Lspc = new ListsSoapClient(Binding, Endpoint);
                var XR = new XmlDictionaryReaderQuotas();
                XR.MaxArrayLength = 2147483647;
                XR.MaxBytesPerRead = 2147483647;
                XR.MaxDepth = 2147483647;
                XR.MaxNameTableCharCount = 2147483647;
                XR.MaxStringContentLength = 2147483647;
                Binding.ReaderQuotas = XR;
                Lspc.ClientCredentials.Windows.ClientCredential = new NetworkCredential(_UserName, _Password, _Domain);
                Lspc.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
                return Lspc;
            private string CreatePayload()
                /* query the list to see if the item can be found
                 * this checks the List*/
                XElement returnedXML = QueryList("ID");
                //get the count; 1 or 0
                _ItemCount = returnedXML.Descendants().First().
                string PayLoad = string.Empty;
                //if found
                if (_ItemCount == "1")
                    //get sharepoint id 
                    XElement ListItem = returnedXML.Descendants().Descendants().First();
                    _listId = ListItem.Attribute("ows_ID").Value;
                    //check if item has been created
                    _Item.IsCreated = (ListItem.Attribute("ows_ID") != null) ? true : false;
                    #region If item has site
                    /* If Item has been created in list */
                    if (_Item.IsCreated)
                        //get path
                        _lspc = CreateProxy(_ProjectsURL + "/_vti_bin/Lists.asmx");
                        returnedXML = QueryList("ID");
                        //change the id to the id of the item
                        //put a check in to for count
                        _listId = returnedXML.Descendants().Descendants().
                    return _Item.ReturnUpdateXMLPayload(_listId);
                return _Item.ReturnInsertXMLPayload();
            public virtual XmlNode Update(IFWCHandler item)
     _Item = item;
                //create payload for insert update
                string PayLoad = CreatePayload();
                //get list to update / insert to
                _xmlDoc = GetXmlDoc();
                XmlElement batchElement = _xmlDoc.CreateElement("Batch");
                //create payload attributes
                batchElement.SetAttribute("OnError", "Return");
                batchElement.SetAttribute("ListVersion", "1");
                //attach payload
                batchElement.InnerXml = PayLoad;
                //update and return result
                XElement ReturnedXML = _lspc.UpdateListItems(_ListName, Helpers.XmlElementToXelement(batchElement));
                #region handle errors
                using (XmlReader reader = ReturnedXML.CreateReader())
                    _xmlDoc = GetXmlDoc();
                    return _xmlDoc;
            private XElement QueryList(string ViewFields)
                _xmlDoc = GetXmlDoc();
                XmlElement Query = _xmlDoc.CreateElement("Query");
                XmlElement vFields = _xmlDoc.CreateElement("ViewFields");
                XmlElement QueryOptions = _xmlDoc.CreateElement("QueryOptions");
                QueryOptions.InnerXml = "";
                //create viewfields
                string fields = string.Empty;
                if (ViewFields == null)
                    throw new Exception("ViewFields cannot be null in method QueryList()");
                    fields += "<FieldRef Name='" +ViewFields + "' />";
                vFields.InnerXml = fields;
                Query.InnerXml = _Item.QueryXML();
                return _lspc.GetListItems(_ListName,
            private XmlDocument GetXmlDoc()
                if (_xmlDoc == null)
                    return new XmlDocument();
                return _xmlDoc;
            private void ThrowExceptionIfErrorsFound(XElement xmlToCheck)
                XNamespace NS = "";
                //check if there are any error tags returned
                List<XElement> query = (from e in xmlToCheck.Descendants()
                                        where e.Name == NS + "ErrorCode" || e.Name == NS + "ErrorText"
                                        select e).ToList();
                XElement ErrorXElement = query.Find(i => i.Value != "0x00000000");
                //if error found then format string and throw exception
                if (ErrorXElement != null)
                    string s = string.Empty;
                    foreach (XElement q in query)
                        s += q.Value + "\n";
                    s += "\nAccount " + _UserName + "\nDomain " + _Domain;
                    throw new Exception("Sorry an error has occurred\n" + s);

    When tries to send url for site with "https://" it dont cause any issue, run successfully.

    When tried to send site url, list which is under site collection"http://", exits from line : 

    XElement returnedXML = QueryList("ID");

    and starts giving error : "The provided URI scheme 'http' is invalid; expected 'https'.\r\nParameter name: via"

    app.config of solution is as follows:

    <?xml version="1.0" encoding="utf-8" ?>
                    <binding name="ListsSoap">
                      <security mode="Transport">
                        <transport clientCredentialType="Ntlm" />
                    <binding name="ListsSoap1" />
                <endpoint address=""
                    binding="basicHttpBinding" bindingConfiguration="ListsSoap"
                    contract="ListServiceReference.ListsSoap" name="ListsSoap" />

    Please advise.

    Really stucked on this.

    Sunday, March 12, 2017 1:52 AM


  • Thanks for all reply.

    When I tried to replace 

    ar Binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
    var Binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly)

    it works successfully for "http://". 

    After adding above "app.config" automatically gets updated as follows:

    <?xml version="1.0" encoding="utf-8" ?>
                    <binding name="ListsSoap" />
                <endpoint address=""
                    binding="basicHttpBinding" bindingConfiguration="ListsSoap"
                    contract="ListServiceReference.ListsSoap" name="ListsSoap" />
    Thanks for all help.

    • Edited by Jayashri10 Friday, March 24, 2017 5:59 AM
    • Marked as answer by Jayashri10 Friday, March 24, 2017 5:59 AM
    Friday, March 24, 2017 5:56 AM

All replies