Trước khi bạn downvote, tôi biết có những câu hỏi trùng lặp như thế này, nhưng tôi đã cố gắng và không thành công trong việc tìm kiếm giải pháp chúng. Có thể tôi đã bỏ lỡ một cái gì đó, nhưng tôi vẫn còn tương đối mới để WCF vì vậy một số của nó đi qua đầu của tôi một chút.WCF - Đã xảy ra lỗi khi nhận phản hồi HTTP tới http: // xxxxx/Service/
Tôi đang thực hiện cuộc gọi này trong dịch vụ WCF của tôi:.
public User GetStudentRecord(string userName)
{
try
{
return new DashboardFacade().GetStudentRecord(userName);
}
catch (Exception ex)
{
ServiceFault fault = new ServiceFault();
fault.Operation = "GetStudentRecord";
fault.Reason = "Who knows...";
fault.Message = ex.Message;
throw new FaultException<ServiceFault>(fault, fault.Message, new FaultCode(fault.Reason), fault.Operation);
}
}
DashboardFacade() GetStudentRecord (..) được định nghĩa như thế này:
public User GetStudentRecord(string userName)
{
User user = ctx.Users.Where(x => x.ADUserName == userName).SingleOrDefault();
return user;
}
ctx là DbContext tôi. Tôi đang sử dụng Mã khung thực thể đầu tiên. Đối tượng người dùng trông như thế này:
public class User
{
public User()
{
//UserDetails = new UserDetail();
}
[Key]
public Guid MasterKey { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string ADUserName { get; set; }
public string UserType { get; set; }
public virtual UserDetail UserDetails { get; set; }
public Nullable<DateTime> LastModifiedDate { get; set; }
}
Và cuối cùng, có lẽ bạn cần phải xem web.config về việc áp dụng WCF:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="NotMyDBContextDB" connectionString="[omitted]" providerName="System.Data.SqlClient"/>
<add name="ApplicationContext" connectionString="Data Source=.;Initial Catalog=MyApp;Integrated Security=True;Pooling=False" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
bất cứ ai có thể chỉ cho tôi đến nơi tôi sẽ sai ở đây?
Đây là lỗi chính xác Tôi nhận:
An error occurred while receiving the HTTP response to http://localhost:5843/MyService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
Inner Exception:
The underlying connection was closed: An unexpected error occurred on a receive.
Inner Exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Inner Exception:
An existing connection was forcibly closed by the remote host
Lỗi ở đâu được ném? Chạy dịch vụ của bạn trong trình gỡ lỗi. – dthorpe
Chỉ cần thêm lỗi và các thông báo ngoại lệ bên trong mà tôi nhận được. Tôi có thể chạy nó trong trình gỡ lỗi và nó cho phép tôi bước qua tất cả các mã tôi có ở trên. Một khi tôi rời khỏi GetStudentRecord() gọi trong dịch vụ thực tế tôi nhận được lỗi một vài giây sau đó. – ledgeJumper