简体   繁体   English

ASMX Web服务和远程服务器返回错误:(500)内部服务器错误问题

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

i have developed a very small web service and which is hosted along with our web site. 我已经开发了一个非常小的Web服务,并且与我们的网站一起托管。 our webservice url is http://www.bba-reman.com/Search/SearchDataIndex.asmx 我们的网络服务网址是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 当我使用HttpWebRequest类从Win应用程序调用该Web服务时,出现错误远程服务器返回错误:(500)Internal Server Error

here is code of my win apps from where i am calling web service 这是我从中调用网络服务的Win应用程序的代码

    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()); 我只是不明白这行何时执行StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); then getting the error The remote server returned an error: (500) Internal Server 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? 错误是在Web服务端代码中还是在调用代码中?

help me to fix this issue. 帮助我解决此问题。 thanks 谢谢

Well what i recommend is the following: -you get rid of the httpwebrequest. 好吧,我建议以下内容:-您摆脱了httpwebrequest。

  • add a service reference to your application which will generate the proxy class. 将服务引用添加到您的应用程序,这将生成代理类。

-finally add this code : -最后添加以下代码:

ServiceReference1.SearchDataIndexSoapClient Client = new ServiceReference1.SearchDataIndexSoapClient();
        ServiceReference1.AuthHeader authHead = new ServiceReference1.AuthHeader();
        authHead.Password = "Admin";
        authHead.Username = "Admin";

        Client.Endpoint.Binding.SendTimeout= new TimeSpan(0, 5, 00);
        Console.WriteLine(client.StartIndex(authHead));

That should be it 应该是这样

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 远程服务器返回错误:(500)内部服务器错误Web服务 - The remote server returned an error: (500) Internal Server Error Web service 从Windows服务将数据发布到Web应用程序时出错。“远程服务器返回错误:(500)内部服务器错误。” - Error While posting Data to a web application from a windows service.“The remote server returned an error: (500) Internal Server Error.” 使用c#将图像发布到Web服务器(远程服务器返回错误(500)内部服务器错误) - Post Image to Web Server in c# (The remote Server returned an error (500) Internal Server Error) Mandrill : 远程服务器返回错误:(500) 内部服务器错误 - Mandrill : The remote server returned an error: (500) internal server error 远程服务器返回错误:(500)网站上的内部服务器错误 - The remote server returned an error: (500) Internal Server Error on website 处理远程服务器返回错误:(500)内部服务器错误 - Handling The remote server returned an error: (500) Internal Server Error 未处理WEBException:远程服务器返回错误:(500)内部服务器错误 - WEBException was unhandled: The remote server returned an error: (500) Internal Server Error .ashx-远程服务器返回错误:(500)内部服务器错误 - .ashx - The remote server returned an error: (500) Internal Server Error 远程服务器返回错误:(500)Internal Server Error。 - The remote server returned an error: (500) Internal Server Error. HttpWebRequest的。 远程服务器返回错误:(500)内部服务器错误 - HttpWebRequest. The remote server returned an error: (500) Internal Server Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM