C# HttpWebRequest.GetResponse提供内部服务器错误

C# HttpWebRequest.GetResponse提供内部服务器错误,c#,web-services,http-post,internal-server-error,protocolexception,C#,Web Services,Http Post,Internal Server Error,Protocolexception,我想使用HTTPPOST方法向web服务发出请求。这是我的C语言代码 下面是我在web服务配置文件中的配置: <configuration> <system.web> <webServices> <protocols> <add name="HttpSoap"/> <add name="Documentation"/>

我想使用HTTPPOST方法向web服务发出请求。这是我的C语言代码

下面是我在web服务配置文件中的配置:

<configuration>
  <system.web>
    <webServices>
        <protocols>
            <add name="HttpSoap"/>              
            <add name="Documentation"/>
            <add name="HttpPostLocalhost"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>

在Main中,当我调试
WebResponse=request.GetResponse()时行,我得到协议错误状态的内部服务器错误(500)


有什么想法吗?谢谢大家。

将此代码与Try-and-Catch方法一起使用

try
{
  // Your Code 
}

catch(Exception wex)
{
  string pageContent = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd().ToString();
  return pageContent;
}

为什么不使用常规的网络参考或WCF?
<configuration>
  <system.web>
    <webServices>
        <protocols>
            <add name="HttpSoap"/>              
            <add name="Documentation"/>
            <add name="HttpPostLocalhost"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>
try
{
  // Your Code 
}

catch(Exception wex)
{
  string pageContent = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd().ToString();
  return pageContent;
}