Re: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.



Are you sending the proper XML message (SOAP)? If your message isn't
formatted properly, you will definately get a server 500 error back.
It looks liek you are actually just sending text ("Hi"). That's not a
proper SOAP message. Here is a sample of a SOAP message:
http://www.w3.org/2004/06/03-google-soap-wsdl.html .

I personally much of web services manually because it's just easier to
interop with COM that way.

Here's part of what I do... (also be sure to set your SOAPAction in the
http header!) messageData hold my XML message I'm sending.

ASCIIEncoding encoding = new ASCIIEncoding( );
byte[] buffer = encoding.GetBytes(messageData);

HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create(this.EndPoint);
myRequest.Method = "POST";
myRequest.ContentType = "text/xml";
myRequest.ContentLength = buffer.Length;
myRequest.Headers.Add(String.Format("SOAPAction: \"{0}\"",
operationName));
myRequest.Timeout = 10000;

using (Stream newStream = myRequest.GetRequestStream( )) {
newStream.Write(buffer, 0, buffer.Length);
newStream.Close( );
}

HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myRequest.GetResponse( );

string rawResponse =
GetWebResponseString(myHttpWebResponse);

myHttpWebResponse.Close( );

Here is the GetWebResponseString method...

private static string GetWebResponseString(WebResponse
myHttpWebResponse) {
StringBuilder rawResponse = new StringBuilder( );
using (Stream streamResponse =
myHttpWebResponse.GetResponseStream( )) {
using (StreamReader streamRead = new
StreamReader(streamResponse)) {
Char[] readBuffer = new Char[256];
int count = streamRead.Read(readBuffer, 0, 256);

while (count > 0) {
String resultData = new String(readBuffer, 0,
count);
rawResponse.Append(resultData);
count = streamRead.Read(readBuffer, 0, 256);
}
}
}
return rawResponse.ToString( );
}

Look closely at what is returned. You may actually be getting the
reason for the fault in the message.

Also, if all is successful, you will get an XML message back. Are you
prepared to parse it?

You may want to actually use the .NET web service mechanism if you
don't want to do everything manually. Since you aren't using the .NET
web service mechanism the web.config configuration doesn't apply.

If you are intending to use .NET for web services, then all you have to
do is add the WSDL file as a web reference and use it as though it were
local. There's not really much work to it. If that is the case then
everything I said above is void, since this is the manual way to do it.

.



Relevant Pages

  • Re: Creating Generic Class from 2 classes
    ... The Web Services are written in Java and we just have access to them. ... We have another problem with multiple defined arrays (string ... It can't seem to find the newHireService. ... the properties in the DataBean from the program that calls the Services. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: SOAP, WSIT, Im LOST, sort of...
    ... Now I've been asked to evaluate "WEB Services" ... I use SOAP to communicate with several other companies that I don't know ... protocol (the Simple Object Access Protocol; ... On the VMS system this mail is taken care ...
    (comp.os.vms)
  • Re: SP1 Problem SOAPException doesnt return quote and Umlaute correcty
    ... I almost started to believe either we are the only ones using the SOAPException fault string with special characters or almost no one uses SOAP Webservices in .net productivly today. ... Our app returns XML in the fault string. ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Creating Generic Class from 2 classes
    ... The Web Services are written in Java and we just have access to them. ... It can't seem to find the newHireService. ... public string GetNewsItem ... The DataBean in Java is just a structure. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problems in transferring XML
    ... I mange to zip the data and get it into a string. ... Zipped data uses all 256 byte values, including some which XML 1.0 ... probably have to do a base-64 encoding, to include it in a SOAP message. ... ASCII Ribbon Campaign | Joe Kesselman ...
    (comp.text.xml)