在你冷靜下來之前,我知道有這樣的重複問題,但我嘗試過並沒有成功找到解決方案他們。可能是我錯過了一些東西,但對於WCF我還是比較新的,所以有些東西有點過頭了。WCF - 接收HTTP響應時發生錯誤http:// xxxxx/Service/
我提出這一呼籲在我的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(..)的定義是這樣的:
public User GetStudentRecord(string userName)
{
User user = ctx.Users.Where(x => x.ADUserName == userName).SingleOrDefault();
return user;
}
CTX是我的DbContext。我首先使用實體框架代碼。用戶對象是這樣的:
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; }
}
最後,你可能需要看到在WCF應用程序的Web.config:
<?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>
任何人都可以指向我,我錯了這裏在哪裏?
這是確切的錯誤我收到:
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
凡被拋出的錯誤?在調試器中運行您的服務。 – dthorpe 2013-04-04 21:21:50
剛剛添加了我收到的錯誤和內部異常消息。我可以在調試器中運行它,它可以讓我逐步瞭解上面所有的代碼。一旦我在實際服務中離開GetStudentRecord()調用,幾秒鐘後我會收到錯誤。 – ledgeJumper 2013-04-04 21:30:13