4

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;
}

3 Answers 3

9

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.

2
  • 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! Aug 16, 2012 at 20:50
  • It worked for me Jul 14, 2016 at 12:09
2

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.

0

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.

1
  • 2
    That is an issue, but it would cause a 401 error not a 500 error. Aug 16, 2012 at 20:48

Your Answer

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

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