5

When I execute the following code:

var context = new ClientContext("https://somehost/somesite");
FormsAuthenticationLoginInfo login = new FormsAuthenticationLoginInfo("jesuslogin", "mypassword");
context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
context.FormsAuthenticationLoginInfo = login;
context.Load(context.Web);
context.ExecuteQuery();

I receive the following exception on context.ExecuteQuery():

System.Web.Services.Protocols.SoapException:

Possible SOAP version mismatch: Envelope namespace https://schemas.xmlsoap.org/soap/envelope/ was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope/.

Please note that the only difference is http versus https.

This is the call stack:

   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at Microsoft.SharePoint.Client.Application.Authentication.Login(String username, String password)
   at Microsoft.SharePoint.Client.FormsAuthenticationLoginInfo.Login(Uri contextUri)
   at Microsoft.SharePoint.Client.FormsAuthenticationLoginInfo.EnsureLogin(Uri contextUri)
   at Microsoft.SharePoint.Client.ClientRuntimeContext.FormsAuthenticationLogin(ClientRuntimeContext context, HttpWebRequest request)
   at Microsoft.SharePoint.Client.ClientRuntimeContext.SetupRequestCredential(ClientRuntimeContext context, HttpWebRequest request)
   at Microsoft.SharePoint.Client.SPWebRequestExecutor.GetRequestStream()
   at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
   at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()

Please help. How to fix the SOAP version mismatch error?

EDIT: Server version is SharePoint Server 2013. I'm using Visual Studio 2013 update 4, .NET Fx 4.0, Microsoft.SharePoint.Client version 15.0.0.0 and Microsoft.SharePoint.Client.Runtime version 15.0.0.0

The following is the request as seen by Fiddler:

POST https://somehost/_vti_bin/authentication.asmx HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.34209)
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/Login"
Host: somehost
Content-Length: 395
Expect: 100-continue
Connection: Close
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <Login xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <username>jesuslogin</username>
      <password>mypassword</password>
    </Login>
  </soap:Body>
</soap:Envelope>

And the following is the response:

HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-SharePointHealthScore: 0
X-AspNet-Version: 4.0.30319
Set-Cookie: blah blah; path=/; secure; HttpOnly
SPRequestGuid: c82aed9c-e154-d0f2-a219-eb2e481881ce
request-id: c82aed9c-e154-d0f2-a219-eb2e481881ce
X-FRAME-OPTIONS: SAMEORIGIN
SPRequestDuration: 75
SPIisLatency: 6
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 15.0.0.4535
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
Date: Wed, 25 Feb 2015 11:29:27 GMT
Connection: close
Set-Cookie: blah blah; path=/
Vary: Accept-Encoding
Content-Length: 461

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <LoginResponse xmlns="https://schemas.microsoft.com/sharepoint/soap/">
      <LoginResult>
        <CookieName>FedAuth</CookieName>
        <ErrorCode>NoError</ErrorCode>
        <TimeoutSeconds>1800</TimeoutSeconds>
      </LoginResult>
    </LoginResponse>
  </soap:Body>
</soap:Envelope>

EDIT:

I Suspect it might be a SharePoint bug or a "smart" proxy that modifies the SharePoint http response.

I'm investigating the issue and considering the use of FiddleCore to fix the response.

0

I finally got around the issue. I fixed the response using FiddlerCore, replacing https xmls namespaces with http namespaces.

I have this class that is acting as an http proxy and is responsible for fixing the respose:

using Fiddler;
using Org.BouncyCastle.Security.Certificates;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ProxyTest
{
    public class HttpProxy 
    {
        public void StartUp()
        {
            FiddlerApplication.ResponseHeadersAvailable += FiddlerApplication_ResponseHeadersAvailable;
            FiddlerApplication.BeforeResponse += FiddlerApplication_BeforeResponse;
            FiddlerApplication.Startup(7897, FiddlerCoreStartupFlags.CaptureLocalhostTraffic | FiddlerCoreStartupFlags.ChainToUpstreamGateway | FiddlerCoreStartupFlags.DecryptSSL | FiddlerCoreStartupFlags.MonitorAllConnections);
        }

        public void ShutDown()
        {
            FiddlerApplication.Shutdown();
        }

        void FiddlerApplication_ResponseHeadersAvailable(Session session)
        {
            if (!session.oResponse.headers.Any(x => x.Name == "MicrosoftSharePointTeamServices")) return;
            if (!session.oResponse.headers.Any(x => x.Name == "Content-Type" && x.Value != null && x.Value.StartsWith("text/xml"))) return;
            session.bBufferResponse = true;
        }

        const string WrongSchemas ="https://schemas.";
        const string RightSchemas = "http://schemas.";
        const string WrongW3c = "https://www.w3.org";
        const string RightW3c = "http://www.w3.org";

        void FiddlerApplication_BeforeResponse(Session session)
        {
            if (!session.bBufferResponse) return;
            if (!session.bHasResponse) return;
            var response = session.GetResponseBodyAsString().Replace(WrongW3c, RightW3c).Replace(WrongSchemas, RightSchemas);
            using (var stream = new MemoryStream())
            using (var writer = new StreamWriter(stream, Encoding.UTF8))
            {
                writer.Write(response);
                writer.Close();
                session.ResponseBody = stream.ToArray();
            }
        }
    }
}

And the following is the main entry point of the console application:

using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace ProxyTest
{
    class Program
    {
        static void Main(string[] args)
        {
            ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
            try
            {
                var httpProxy = new HttpProxy();
                httpProxy.StartUp();
                Login();
                Console.WriteLine("Login sucess.. Hurray!!");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                Fiddler.FiddlerApplication.Shutdown();
            }
            Console.WriteLine("Press enter to exit..");
            Console.ReadLine();
        }

        static void Login()
        {
            var context = new ClientContext("https://somehost/somesite");
                FormsAuthenticationLoginInfo login = new FormsAuthenticationLoginInfo("jesuslogin", "jesuspassword");
                context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
                context.FormsAuthenticationLoginInfo = login;
                context.Load(context.Web);
                context.ExecuteQuery();
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.