매개 변수 P1, P2, P3, P4 걸릴 WCF를 사용하여 REST 서비스를 구현하고 쿼리를 수행하고 결과를 반환하는 저장 프로 시저로 전달하려고합니다.WCF REST WebServiceHostFactory SQL에 linq 사용
나는 서비스에 대한 C#에서이 코드를 가지고 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.ServiceModel.Activation;
using System.Data;
namespace RestServicePublishing
{
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[ServiceContract]
public class RestService
{
[OperationContract]
[WebGet]
public List<Simulated_service_State> GetState(decimal P1, decimal P2, decimal P3, decimal P4)
{
using (ServiceDataContext db = new ServiceDataContext())
{
List<Simulated_service_State> states =
db.GetStateByLongLat(P1, P2, P3, P4).ToList();
db.SubmitChanges();
return states;
}
}
}
}
Simulated_Service_State
내가 저장 프로 시저 호출의 결과를 저장하고있어 할 수있는 임시 테이블입니다. 브라우저를 통해 웹 서비스를 호출하면 다음 오류가 발생합니다.
Request Error
The server encountered an error processing the request. The exception message is 'Object reference not set to an instance of an object.'. See server logs for more details. The exception stack trace is:
at RestServicePublishing.ServiceDataContext..ctor() in C:....\RestServicePublishing\Service.designer.cs:line 39 at RestServicePublishing.RestService.GetState(Decimal P1, Decimal P2, Decimal P3, Decimal P4) in C:....\RestServicePublishing\RestService.svc.cs:line 42 at SyncInvokeGetState(Object , Object[] , Object[]) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
!!! 내가 전화
URL은 다음
http://localhost/RestServicePublishing/RestService.svc/GetState?P1=14&P2=13&P3=22&P4=55
사람이 저장 프로 시저 및 REST WCF 서비스와 함께 작동하는 방법을 이해하는 데 도움이 수 있습니까? 임시 테이블에서 클라이언트로 값을 반환하는 방법
업데이트 그래서 내가 여기를 게시하도록하겠습니다 코멘트 섹션에 모든 데이터를 게시 할 수 없습니다. 이것은 내가 지금 사용하고 코드이지만, 그것은 나에게 내 쿼리가 테이블에서 아무것도 선택하지 않음을 의미 결과로 0을주고 :
public class RestService
{
[OperationContract]
[WebGet (ResponseFormat = WebMessageFormat.Xml)]
public string GetState(decimal P1, decimal P2, decimal P3, decimal P4)
{
IList<Simulated_service_State> query = new List<Simulated_service_State>();
IList<string> Mac = new List<string>();
int j;
int jj;
using (ServiceDataContext db = new ServiceDataContext())
{
query = db.GetStateByLongLat1(P1, P2, P3, P4).ToList();
db.SubmitChanges();
var query2 = from Simulated_service_State state in db.Simulated_service_States
select state.MAC;
Mac = query2.ToList();
jj = Mac.Count;
j = query.Count;
}
return j.ToString() + "," + jj.ToString();
}
}
이 코드 (하지 저장 프로 시저를 사용하는 경우) 내가 SQL에 LINQ 잘 (ServiceDataContext 작동한다고 가정 그래서 내가) 테이블에서 결과를 받고 있어요 : 내가 얻을
public class RestService
{
[OperationContract]
[WebGet (ResponseFormat = WebMessageFormat.Xml)]
public string GetState(decimal P1, decimal P2, decimal P3, decimal P4)
{
IList<Simulated_service_State> query = new List<Simulated_service_State>();
IList<string> Mac = new List<string>();
int j;
int jj;
using (ServiceDataContext db = new ServiceDataContext())
{
var query3 = from SimulatedNode node in db.SimulatedNodes
select node.MAC;
Mac = query3.ToList();
j = (Mac.Count);
}
return j.ToString();
결과는 목록의 항목 수를 나타냅니다 4입니다.
어떻게 진행할 수 있습니까?
그럼'GetState' 메쏘드로 디버깅해서 ** 무엇이 NULL인지 알 수 있습니까 ?? –
당신의'ServiceDataContext'가 어떤 이유인지 (그 이유가 무엇인지는 모르겠다) 만들 수 없다고 가정합니다 - 오류 메시지가 가리키는 것입니다 ... –
불행히도 디버거로 코드를 실행할 수 없습니다. 여기에서 지침을 기반으로 web.config 파일을 설정했습니다. http://msdn.microsoft.com/en-us/library/bb157687.aspx 그러나 코드를 디버깅 할 수 없습니다. 코드를 단계적으로 실행하는 방법에 대한 아이디어가 있습니까? – Mark