首页 > 解决方案 > 如何定位网络服务主机点

问题描述

这是我在 Stackoverflow 上的第一个问题。如果我犯了任何错误,请给我这个问题的减分,但请让我知道如何改进这个问题。在花了相当多的时间讨论上述问题后,我决定提出这个问题。我最近加入了一家开发 Windows 应用程序的公司。它有一个服务器 EXE 和一个客户端 EXE。服务器 EXE 与 Web 服务通信以获取最新更新和用户注册信息。它使用以下代码来测试 Web 服务的可用性。

private void testWebService()
{
    if (WebServiceClient.IsValidHttpAddress(txtWebserviceURL.Text))
    {
        WebServiceClient svc = new WebServiceClient(new Uri(txtWebserviceURL.Text), txtWebserviceUserName.Text, txtWebservicePassword.Text);

        string response;
        if (svc.CheckWebResponse(new UserEndPoint(), out response))
        {
            //Mark the webservice url as read only again
            txtWebserviceURL.ReadOnly = true;
        }
        MessageBox.Show(response, "Web Service Reponse", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    else
        MessageBox.Show(string.Format("URL of '{0}' is invalid.{1}{1}It should start with 'http'.", txtWebserviceURL.Text, System.Environment.NewLine), "Web Service URL", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

当我让上面的方法被执行时,最终它调用了下面的方法并返回了一个异常——“远程服务器返回错误:(500)内部服务器错误。”

    /// <summary>
    /// Gets a web response from the web service on the required endpoint.
    /// </summary>
    /// <param name="pEndPoint">The endpoint to connect to the web service with.</param>
    /// <returns>The response returned from the web request.</returns>
    private HttpWebResponse GetWebResponse(WebServiceEndPointBase pEndPoint)
    {
        WebRequest fRequest = WebRequest.Create(pEndPoint == null ? this.Url : pEndPoint.GetEndPointUrl(this.Url));
        fRequest.ContentType = "application/json";
        fRequest.Headers.Add("Authorization", "Basic " + this.Credentials);
        fRequest.Method = "GET";
        fRequest.Timeout = this.Timeout;

        HttpWebResponse fResponse = fRequest.GetResponse() as HttpWebResponse;
        return fResponse != null && fResponse.StatusCode == HttpStatusCode.OK ? fResponse : null;
    }

我相信网络服务由于某种原因停止了。由于我是公司的新手,并且没有记录与 Web 服务相关的信息,因此我无法确定 Web 服务的托管位置。Web 服务名称是“http://services.mycomanyname.com.au”。

到目前为止我做了什么。

我想要的是

  1. 请建议我找到托管 Web 服务的位置。目前,向现有员工询问不是我的选择。
  2. 请指导我获取500错误的原因。

标签: c#resthttpweb-services

解决方案


推荐阅读