[英]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
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
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。
-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.