1

I need to request webservices through forefront endpoint. I use basic authentication. it work perfectly if I use this code :

Uri uri = new Uri("https://ged.legrandnarbonne.com/_vti_bin/webs.asmx");
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

        System.Net.CredentialCache credentialCache = new System.Net.CredentialCache();
        credentialCache.Add(
            new System.Uri("https://xxx.com"),
            "Basic",
            new System.Net.NetworkCredential("xxx", "xxxx")
        );
        string postData = @"<?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><GetWeb xmlns='http://schemas.microsoft.com/sharepoint/soap/'><webUrl>https://ged.legrandnarbonne.com</webUrl></GetWeb></soap:Body></soap:Envelope>";
        byte[] byteArray = Encoding.UTF8.GetBytes (postData);
        request.ContentType = "text/xml; charset=utf-8";

        request.Credentials=credentialCache;
        request.Method = "POST";
        request.ContentLength=byteArray.Length;
        Stream dataStream = request.GetRequestStream ();
        dataStream.Write (byteArray, 0, byteArray.Length);
        dataStream.Close ();

        WebResponse v = request.GetResponse();
        Stream rStream = v.GetResponseStream();
        StreamReader str = new StreamReader(rStream);
        if (str.EndOfStream != true)
        {
            Console.WriteLine(str.ReadToEnd());
        }
        v.Close();
        rStream.Close();
        str.Close();

I got a 401 response and then authentication is send and I got the response.

If I use SoapHttpClientProtocol, I have a 302 response and I don't now how to handle this. Could you help me.

1 Answer 1

1

After a long investigation it look like redirection is due to "useragent" header. if it is set TMG send a 302 to redirect request to the login page. If it's left blank it work perfectly. Hope this can help someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.