在WebException中,我看不到GetResponse的主体.这是我在C#中的代码:
try {                
  return GetResponse(url + "." + ext.ToString(), method, headers, bodyParams);
} catch (WebException ex) {
    switch (ex.Status) {
      case WebExceptionStatus.ConnectFailure:
         throw new ConnectionException();                        
     case WebExceptionStatus.Timeout:
         throw new RequestTimeRanOutException();                     
     case WebExceptionStatus.NameResolutionFailure:
         throw new ConnectionException();                        
     case WebExceptionStatus.ProtocolError:
          if (ex.Message == "The remote server returned an error: (401) unauthorized.") {
              throw new CredentialsOrPortalException();
          }
          throw new ProtocolErrorExecption();                    
     default:
          throw;
    }
我看到头但我看不到身体.这是Wireshark输出的请求:
POST /api/1.0/authentication.json HTTP/1.1    
Content-Type: application/x-www-form-urlencoded    
Accept: application/json    
Host: nbm21tm1.teamlab.com    
Content-Length: 49    
Connection: Keep-Alive    
userName=XXX&password=YYYHTTP/1.1 500 Server error    
Cache-Control: private, max-age=0 …我有一个测试Web服务的诊断工具.
我希望工具在出现问题时进行报告,因此我已经部署了一个服务,但合同有问题需要对其进行测试.
当我浏览它时,我得到一个带有描述性信息的页面,例如:
ExceptionDetail,可能由IncludeExceptionDetailInFaults = true创建,其值为:System.InvalidOperationException:在对WSDL导出扩展的调用中抛出异常:
System.ServiceModel.Description.DataContractSerializerOperationBehavior contract:类型XXX的DataContract无法添加到DataContractSet中在名称空间XXX中具有相同数据合同名称XXX的类型XXX已经存在且合同不等同等.
我想要的是能够打电话:
myErrorMsg = WebClient.DownloadString("MyBadService.svc");
并将此有用的错误消息作为字符串,但我得到以下WebException:
远程服务器返回错误:(500)内部服务器错误.
如何获得在浏览器中收到的相同错误消息作为字符串返回,而不会出现异常?
谢谢.