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

我已经开发了一个非常小的Web服务,它与我们的网站一起托管。我们的网络服务网址是http://www.bba-reman.com/Search/SearchDataIndex.asmx

网络服务代码

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

}

当我使用HttpWebRequest从我的Win应用程序中调用该Web服务时出现错误远程服务器返回错误:(500)Internal Server Error

这是我从中调用网络服务的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();

我只是无法理解何时执行此行,StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());然后得到错误远程服务器返回错误:(500)Internal Server Error

无法理解我在哪里犯了错误。错误是在Web服务端代码中还是在调用代码中?

帮助我解决此问题。谢谢

编码器1409

好吧,我建议以下内容:-您摆脱了httpwebrequest。

  • 在您的应用程序中添加一个服务引用,该引用将生成代理类。

-最后添加以下代码:

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));

应该是这样

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

javascript 500内部服务器错误

来自分类Dev

CakePHP 500内部服务器错误

来自分类Dev

Ajax:500内部服务器错误

来自分类Dev

AJAX 500(内部服务器错误)

来自分类Dev

MS版本管理-远程服务器返回错误:(500)内部服务器错误

来自分类Dev

给定解析器错误,将asmx Web服务发布到FTP服务器

来自分类Dev

ASMX Web服务“服务器无法识别HTTP标头SOAPAction的值”

来自分类Dev

500内部服务器错误Heroku

来自分类Dev

Web服务(.asmx)在IIS 7中引发404错误

来自分类Dev

远程服务器返回错误500-调用Soap Web服务时出错

来自分类Dev

内部服务器500错误-Django

来自分类Dev

从跨域调用asmx服务

来自分类Dev

远程服务器返回错误:(500)网站上的内部服务器错误

来自分类Dev

异步/等待对asmx服务的调用

来自分类Dev

POST 500(内部服务器错误)

来自分类Dev

AJax内部服务器错误500

来自分类Dev

远程服务器返回错误:(500)System.Net.HttpWebRequest.GetResponse()上的服务器上的内部服务器错误。

来自分类Dev

nginx 500内部服务器错误

来自分类Dev

AJAX 500(内部服务器错误)

来自分类Dev

MS版本管理-远程服务器返回错误:(500)内部服务器错误

来自分类Dev

Laravel 500内部服务器错误?

来自分类Dev

得到500内部服务器错误?

来自分类Dev

unity 500内部服务器错误

来自分类Dev

500内部服务器错误Heroku

来自分类Dev

通过AJAX的ASMX调用返回内部服务器错误

来自分类Dev

ASMX到64位服务器中的COM调用

来自分类Dev

htacces 500内部服务器错误

来自分类Dev

将 asmx Web 服务部署到共享托管服务器

来自分类Dev

如何在服务器端获取被调用的 webservice.asmx 的方法名称

Related 相关文章

热门标签

归档