Zanim się zgodzisz, wiem, że są tam zduplikowane pytania, takie jak ten, ale próbowałem i nie udało mi się znaleźć rozwiązania w im. Możliwe, że coś mi umknęło, ale wciąż jestem względnie nowy w WCF, więc część z nich trochę mi idzie na głowę.WCF - Wystąpił błąd podczas odbierania odpowiedzi HTTP na http: // xxxxx/Service/
Robię to wezwanie w moim usług WCF.
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 (..) jest zdefiniowana następująco:
public User GetStudentRecord(string userName)
{
User user = ctx.Users.Where(x => x.ADUserName == userName).SingleOrDefault();
return user;
}
ctx jest mój DbContext. Używam Entity Framework Code First. Zadaniem użytkownika wygląda następująco:
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; }
}
I wreszcie, prawdopodobnie trzeba zobaczyć na web.config aplikacji 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>
Czy ktoś może wskazać mi gdzie wezwę niewłaściwy tutaj?
ta jest dokładna błąd otrzymuję:
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
Gdzie jest błąd wyrzucane? Uruchom usługę w debugerze. – dthorpe
Po prostu dodałem komunikat o błędzie i wewnętrzne wiadomości wyjątku, które otrzymuję. Mogę uruchomić go w debugerze i pozwala mi przejść przez cały kod, który mam powyżej. Po opuszczeniu funkcji GetStudentRecord() w rzeczywistej usłudze pojawia się błąd kilka sekund później. – ledgeJumper