Avatar of Steve Endow
Steve Endow
Flag for United States of America

asked on 

asmx web service: IIS 500 Internal Server error from POST from external app, but no error when testing with IE

I inherited a C# asmx web service and I have upgraded it to VS 2015, made a few minor changes to its internal processing, and am now trying to deploy it to a new Windows Server 2012 R2 machine.

I have IIS configured and the web service installed. I can access the asmx page with IE. When I click on the Invoke button, the POST is successfully submitted and the page code fires.

When the external trading partner tries to submit a POST, they get a 500 response code.

To troubleshoot this, I created a testing app to perform a POST to the web service.  When I try and submit a POST using the test app, I get a 500 Internal Server Error and the page code is not fired. It appears that IIS is immediately encountering an error with the POST request and returns the error.

In my testing app, I've tried two different POST methods:  HttpWebRequest and WebClient.  Both return the same 500 error, and the web service code is never invoked and no breakpoints are hit in the code.

Since the web service appears to work when accessed via IE and seems to accept a POST via browser, it seems like the page code works, but I can't tell if this is an IIS configuration issue or an issue with my test app.

No error messages are logged to the Windows Event Viewer Application or System log.  The IIS log only shows a 500 error.  

2016-04-07 15:26:47 POST /JAInBoundWebService/ReceiveRRDxml.asmx/ReceiveXmlFromRRD - 81 - - - 500 0 0 121

Open in new window

I have  set debug true, custom errors off, and error mode detailed, but I'm not seeing any additional error information--where else can I look?

        <httpErrors errorMode="Detailed" />
    <compilation debug="true" targetFramework="4.5.1"/>
    <customErrors mode="Off" />
    <authentication mode="Windows"/>
    <httpRuntime executionTimeout="1200" maxRequestLength="16384"/>
        <add name="HttpPost"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>

Open in new window

Here is the code for the two post methods that I'm trying in my test app.

public static string CreateHttpPostRequest(string postData)
                ASCIIEncoding encoding = new ASCIIEncoding();
                byte[] byte1 = encoding.GetBytes(postData);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Properties.Settings.Default.TestURL);
                request.Timeout = System.Convert.ToInt32(10000);
                request.Credentials = new NetworkCredential(Properties.Settings.Default.Username, Properties.Settings.Default.Password);
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                //request.ContentType = "text/xml";
                request.ContentLength = byte1.Length;

                Stream myStream = request.GetRequestStream();
                myStream.Write(byte1, 0, byte1.Length);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                System.IO.Stream stream = response.GetResponseStream();
                System.Text.Encoding ec = System.Text.Encoding.GetEncoding("utf-8");
                System.IO.StreamReader reader = new System.IO.StreamReader(stream, ec);
                string str2 = reader.ReadToEnd();
                return str2;

            catch (Exception ex)
                return ex.Message;


Open in new window

public static string SimplePost(string postData)
                var wb = new WebClient();

                var data = new NameValueCollection();
                data["xmlDoc"] = postData;

                var response = wb.UploadValues(Properties.Settings.Default.TestURL, "POST", data);

                return Encoding.ASCII.GetString(response);
            catch (Exception ex)
                return ex.Message;

Open in new window

I can access the web service and submit a POST using IE
Clicking on the Invoke button in IE does trigger the web service code
ASP.NETMicrosoft IIS Web Server

Avatar of undefined
Last Comment
Steve Endow

8/22/2022 - Mon