어제 WCF에서 어제 시작한 새내기.Entity Framework 오류가있는 WCF 파트 2
데이터에 Northwind를 사용하고 있으며 고객, 주문, 주문 세부 정보 및 제품 만 모델에 추가 했으므로 멋진 것은 아닙니다.
응용 프로그램을 시작하고 Test를 호출하고 중단 점을 설정하면 제품에 대한 값이 있으며 오류없이 완료됩니다. GetMaxQuantityByOrderID (10248)를 호출하려고하면 맨 아래에 오류가 표시됩니다. 왜 Test()가 작동하고 동일한 메소드 WITHIN Test()가 작동하지 않습니까? 나는 정확히 또 다른 (Test1()을 테스트와 똑같이 추가했다. 문자열 : x.ProductName을 반환한다. 정확히 Queso Cabrales를 표시한다). 다른 메서드 내에서 호출되는 메서드가 작동하지만 직접 호출하면 예외가 발생한다는 것이 이상하게 보입니다.
IEnumerable GetOrders()는 .ToList()를 추가 할 때만 작동한다는 또 다른 문제가 있습니다. (또는 .AsEnumerable()을 사용하지 않으면) 지연로드가 False으로 설정되어 있어도 오류가 발생합니다 (ObjectContext 인스턴스가 삭제되어 더 이상 연결이 필요한 작업에 사용할 수 없습니다.)). 이 논리 뒤에있는 논리는 무엇입니까?
IServiceTest.cs
using System.Collections.Generic;
using System.ServiceModel;
namespace WcfTestServiceLibrary
{
[ServiceContract]
public interface IServiceTest
{
[OperationContract]
IEnumerable<Orders> GetOrders();
[OperationContract]
IEnumerable<Customers> GetCustomers();
[OperationContract]
Customers GetCustomerByID(string customerID);
[OperationContract]
Orders GetOrderByID(int id);
[OperationContract]
IEnumerable<Order_Details> GetOrderDetailsByOrderID(int id);
[OperationContract]
Order_Details GetMaxQuantityByOrderID(int id);
[OperationContract]
void Test();
}
}
ServiceTest.cs
using System.Collections.Generic;
using System.Linq;
namespace WcfTestServiceLibrary
{
public class ServiceTest : IServiceTest
{
public IEnumerable<Orders> GetOrders()
{
using (var ctx = new NWEntities())
{
return (from o in ctx.Orders.Include("Order_Details.Products").Include("Customers")
select o).ToList();
}
}
public IEnumerable<Customers> GetCustomers()
{
using (var ctx = new NWEntities())
{
return (from c in ctx.Customers
select c);
}
}
public Customers GetCustomerByID(string customerID)
{
return (from c in GetCustomers()
where c.CustomerID == customerID
select c).FirstOrDefault();
}
public Orders GetOrderByID(int id)
{
IEnumerable<Orders> orders = GetOrders();
return (from o in orders
where o.OrderID == id
select o).FirstOrDefault();
}
public IEnumerable<Order_Details> GetOrderDetailsByOrderID(int id)
{
return GetOrderByID(id).Order_Details;
}
public Order_Details GetMaxQuantityByOrderID(int id)
{
Orders order = GetOrderByID(id);
return order == null ? null : order.Order_Details.OrderByDescending(x => x.Quantity).FirstOrDefault();
}
public void Test()
{
const int orderID = 10248;
var oq = GetMaxQuantityByOrderID(orderID);
var x = oq.Products;
}
}
}
오류 : 첫 번째 문제의 경우
An error occurred while receiving the HTTP response to http://localhost:8732/Design_Time_Addresses/WcfTestServiceLibrary/Service1/. 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.
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at IServiceTest.GetMaxQuantityByOrderID(Int32 id)
at ServiceTestClient.GetMaxQuantityByOrderID(Int32 id)
Inner Exception:
The underlying connection was closed: An unexpected error occurred on a receive.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
Inner Exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
Inner Exception:
An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
, 나는 ObjectContext는 인스턴스가 배치 된 오류가 더 이상 연결을 요구하는 작업에 사용할 수 없습니다. WCF 서비스를 수행하는 적절한 방법은 무엇입니까? 나는 추적을 구성하는 것이 내가 무엇을 할 수 있는지 이해할 수 없다. 제가 말씀 드렸다시피, 저는 방금 2 일 전에 WCF에서 시작했습니다. –
추적 및 EF에 대한 정보를 추가했습니다. –
이 문제는 WCF 테스트 클라이언트에서만 발생합니다. 클라이언트를 사용하지 않고 결과에 asp.net 페이지를 사용하면 작동합니다. –