Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have an application where I am creating a SOAP request by hand and hitting a SharePoint instance. My problem is that the call returns the error: The remote server returned an error: (500) Internal Server Error. giving me little to go after as far as the cause of the error.

I've checked the ULS logs and Event logs on the target server, but nothing is showing up there. Suggestions on where to look for more info?

More info:

I cannot add a web reference or use wsdl.exe to create a class to make this request, I need to create the SOAP request by hand. Below is the code I am using to make the request:

string soapStr =
    @"<?xml version=""1.0"" encoding=""utf-8""?>
        <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
          <soap:Body>
            <CopyIntoItems xmlns=""http://schemas.microsoft.com/sharepoint/soap/"">
              <SourceUrl>http://devint/a/ceo/Pages/BasePage.aspx<SourceUrl>
              <DestinationUrls>
                <string>http://sptestmnc.nevcounty.net/Resources/Images</string>
              </DestinationUrls>
              <Fields>
                <FieldInformation Type=""Text"" DisplayName=""Title"" InternalName=""Title"" Value=""{0}"" Id=""{{bc91a437-52e7-49e1-8c4e-4698904b2b6d}}"" />
              </Fields>
              <Stream>{1}</Stream>
            </CopyIntoItems>
          </soap:Body>
        </soap:Envelope>";

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
req.Headers.Add("SOAPAction", "\"http://tempuri.org/" + MethodName + "\"");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";

using (Stream stm = req.GetRequestStream())
{

    soapStr = string.Format(soapStr, "testFile.png", content);
    using (StreamWriter stmw = new StreamWriter(stm))
    {
        stmw.Write(soapStr);
    }
}

using (StreamReader responseReader = new StreamReader(req.GetResponse().GetResponseStream()))
{
    string result = responseReader.ReadToEnd();
    ResultXML = XDocument.Parse(result);
    ResultString = result;
}
share|improve this question
add comment

3 Answers 3

up vote 5 down vote accepted

You could user Fiddler. In my experience is the best tools to check what is going on behind the scene when the Browse talks with the SharePoint Server.

http://www.fiddler2.com/fiddler2/version.asp

Also you could use the Developer Tool (F12) on the Internet Explorer 8+ and in the Script tab you can do some javascript debug.

Cheers!

UPDATE:

This problem ended up being caused by the line:

req.Headers.Add("SOAPAction", "\"http://tempuri.org/" + MethodName + "\"");

when I changed it to:

req.Headers.Add("SOAPAction", "\"http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems\"");

the 500 error went away.

share|improve this answer
    
I ended up using fiddler to capture the SOAP request from a working call and from the broken call. After comparing the two I ended up changing the SOAPAction in my request and got past the 500 error. I have added the details of my fix to your answer in case anyone else comes across this. Thanks! –  Abe Miessler Aug 16 '12 at 20:50
    
very helpful , thank u :) –  Mahmoud Farahat Feb 3 '13 at 15:54
add comment

I might sound like a Noob, but I can't see any authentication happening in your piece of code or am i missing something ? I was once trying to use SOAP while coding a gadget for windows 7 to get data from a SharePoint list, but I couldn't by pass ISA server or could find a way.

share|improve this answer
1  
That is an issue, but it would cause a 401 error not a 500 error. –  Abe Miessler Aug 16 '12 at 20:48
add comment

As I'd agree with Javier, I'd like to ask if you're using any proxies or firewalls?

The reason I ask is because you may need to configure your proxy settings accordingly otherwise. If so you'll want to update your code to utilize the system proxy, which pulls from your internet options (in the control panel) :

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
req.Headers.Add("SOAPAction", "\"http://tempuri.org/" + MethodName + "\"");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
req.Proxy = WebRequest.GetSystemWebProxy();

Hope this helps.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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