none
ASMX web service and The remote server returned an error: (500) Internal Server Error issue

    Question

  • i have developed a very small web service and which is hosted along with our web site. our webservice url is http://www.bba-reman.com/Search/SearchDataIndex.asmx

    web service code

    namespace WebSearchIndex
    {
        #region SearchDataIndex
        /// <summary>
        /// SearchDataIndex is web service which will call function exist in another library for part data indexing
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
    
        public class SearchDataIndex : System.Web.Services.WebService
        {
            //public AuthHeader ServiceAuth=null;
            public class AuthHeader : SoapHeader
            {
                public string Username;
                public string Password;
            }
    
            #region StartIndex
            /// <summary>
            /// this function will invoke CreateIndex function of SiteSearch module to reindex the data
            /// </summary>
            [WebMethod]
            public string StartIndex(AuthHeader auth)
            {
                string strRetVal = "";
                if (auth.Username == "Admin" && auth.Password == "Admin")
                {
                    strRetVal = SiteSearch.CreateIndex(false);
                }
                else
                {
                    SoapException se = new SoapException("Failed : Invalid credentials",
                    SoapException.ClientFaultCode,Context.Request.Url.AbsoluteUri,new Exception("Invalid credentials"));
                    throw se;
                }
                return strRetVal;
            }
            #endregion
        }
        #endregion
    
    }

    when i was calling that web service from my win apps using

    HttpWebRequest
    class then getting error The remote server returned an error: (500) Internal Server Error

    here is code of my win apps from where i am calling web service

        string strXml = "";
        strXml = "<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><StartIndex xmlns='http://tempuri.org/' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><auth><Username>joy</Username><Password>joy</Password></auth></StartIndex></s:Body></s:Envelope>";
        string url = "http://www.bba-reman.com/Search/SearchDataIndex.asmx";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Method = "POST";
        req.ContentType = "text/xml";
        req.KeepAlive = false;
        req.ContentLength = strXml.Length;
        StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
        streamOut.Write(strXml);
        streamOut.Close();
        StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
        string strResponse = streamIn.ReadToEnd();
        streamIn.Close();

    i am just not being able to understand when this line execute

    StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
    then getting the error The remote server returned an error: (500) Internal Server Error

    not being able to understand where i made the mistake. mistake is in the code of web service end or in calling code?

    help me to fix this issue. thanks

    Tuesday, March 31, 2015 1:49 PM

Answers

  • Hi Mou,

    I just tried your win app code about calling web service, but failed. I got the 500 error after I called your service:

    The error message I quoted from Fiddler:

    <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>System.Web.Services.Protocols.SoapException: Failed : Invalid credentials ---&gt; System.Exception: Invalid credentials
       --- End of inner exception stack trace ---
       at BBAReman.WebSearchIndex.SearchDataIndex.StartIndex(AuthHeader auth)</faultstring><faultactor>http://www.bba-reman.com/Search/SearchDataIndex.asmx</faultactor><detail /></soap:Fault></soap:Body></soap:Envelope>

    I am not totally sure that error occurred by the authentication. But I suggest you can try to add this service into your project using this method below:

    1.right click the Reference and select Add Service Reference

    2.input your service link and click "Go"

    And you can use this service as the following:

    private async void callService() 
    {          
    
                ServiceReference1.SearchDataIndexSoapClient client =new  ServiceReference1.SearchDataIndexSoapClient();
                var Str= await client.StartIndexAsync(new ServiceReference1.AuthHeader { Username = "Admin", Password = "Admin" });
     }

    Please try it.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Mou_kolkata Thursday, April 2, 2015 7:37 AM
    Thursday, April 2, 2015 3:34 AM

All replies

  • Hi,

    For this situation, you could try to set a proper user-agent in the headers of your request.

    HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
    myHttpWebRequest.UserAgent=".NET Framework Test Client";

    Besides, you could try to use the try catch to check the error message:

    try
    {
    }
    catch (WebException wex)
    {
        var pageContent = new StreamReader(wex.Response.GetResponseStream())
                              .ReadToEnd();
    }

    For more information, you could refer to:

    http://forums.asp.net/t/1411782.aspx?The+remote+server+returned+an+error+500+Internal+Server+Error

    Regards


    Wednesday, April 1, 2015 2:08 AM
    Moderator
  • If the  solution is hosted on IIS did you look at the IIS log for further explaination about the errror?
    Wednesday, April 1, 2015 4:24 PM
  • Hi Mou,

    I just tried your win app code about calling web service, but failed. I got the 500 error after I called your service:

    The error message I quoted from Fiddler:

    <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>System.Web.Services.Protocols.SoapException: Failed : Invalid credentials ---&gt; System.Exception: Invalid credentials
       --- End of inner exception stack trace ---
       at BBAReman.WebSearchIndex.SearchDataIndex.StartIndex(AuthHeader auth)</faultstring><faultactor>http://www.bba-reman.com/Search/SearchDataIndex.asmx</faultactor><detail /></soap:Fault></soap:Body></soap:Envelope>

    I am not totally sure that error occurred by the authentication. But I suggest you can try to add this service into your project using this method below:

    1.right click the Reference and select Add Service Reference

    2.input your service link and click "Go"

    And you can use this service as the following:

    private async void callService() 
    {          
    
                ServiceReference1.SearchDataIndexSoapClient client =new  ServiceReference1.SearchDataIndexSoapClient();
                var Str= await client.StartIndexAsync(new ServiceReference1.AuthHeader { Username = "Admin", Password = "Admin" });
     }

    Please try it.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Mou_kolkata Thursday, April 2, 2015 7:37 AM
    Thursday, April 2, 2015 3:34 AM