Link to home
Create AccountLog in
ASP.NET

ASP.NET

--

Questions

--

Followers

Top Experts

Avatar of Steve Endow
Steve Endow

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 192.168.25.150 POST /JAInBoundWebService/ReceiveRRDxml.asmx/ReceiveXmlFromRRD - 81 - 192.168.25.150 - - 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?

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

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)
        {
            try
            {
                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);
                myStream.Close();
                
                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();
                
                response.Close();
                stream.Close();
                reader.Close();
                
                return str2;

            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }

Open in new window



public static string SimplePost(string postData)
        {
            try
            {
                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


User generated image
User generated image

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


SOLUTION
Avatar of Dan McFaddenDan McFadden🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Steve EndowSteve Endow

ASKER

Hi Dan,

What is strange is that I'm getting zero entries in the Windows Application event log.  Nothing.

I've setup my dev server to debug against IIS and am finally seeing some errors occur in the code when it attempts to retrieve values from the config file, so I'm making some progress.

I suspect I have more than one issue. I did more testing and see that if I POST an empty string using my test app, I get a response from the page (which is the 'root element is missing' error shown in my original post).  But if I attempt to POST an XML doc/string to the page, I get the 500 error.  

The lack of entries in the Application event log must be an issue with my config file--I must not be doing something correctly.

Now that I'm seeing some errors in debug mode, I'm going to dig deeper and see why it can't read from the config file.

Thanks,

Steve

I think I may have found the issue.

When submitting a test POST with IE, if I submit nothing, the page code is fired and works fine, returning the error that there was no root node.

But if I POST *any* XML, I get an immediate 500 error. The page code isn't fired and nothing is logged in the Application log.  But then it dawned on me.  When I submit a snippet of XML, I get this error:  HttpRequestValidationException.  I had seen this previously, but the implications of the message didn't occur to me.

User generated image
User generated image
So it seems that the latest version of IIS has a default security filter to prevent the submission of the XML text.

Any idea how to turn this off?

I'll research the error--I'm guessing I'm not the first person to encounter this issue.

Thanks,

Steve

ASKER CERTIFIED SOLUTION
Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Identified that the issue was due to ASP.NET 4 request validation.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

ASP.NET

ASP.NET

--

Questions

--

Followers

Top Experts

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications