2012-09-11 3 views
1

WCF Data Services를 사용하여 OData 피드의 데이터를 사용해야하는 Windows Phone 응용 프로그램을 개발하고 있습니다.Windows Phone 개발에서 WCF Data Services (ODATA) 작업 사용

: 특히, 나는 브라우저 (크롬)에서이를 실행하면이

<feed xml:base="http://[redacted]/OData/PIDataService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> 
<title type="text">RecordedValues</title> 
<id>http://[redacted]/ODATA/PIDataService.svc/RecordedValues</id> 
<updated>2012-09-11T12:09:12Z</updated> 
<link rel="self" title="RecordedValues" href="RecordedValues"/> 
<entry> 
<id>http://[redacted]/OData/PIDataService.svc/TimeseriesValues(SourceAttributePath='//OPENXC/OpenXC/EventFrames%5BtestFrame%5D%7CSinusoid',Timestamp=datetime'2012-09-10T13%3A31%3A09Z')</id> 
<title type="text"/> 
<updated>2012-09-11T12:09:12Z</updated> 
<author> 
<name/> 
</author> 
<link rel="edit" title="TimeSeriesValue" href="TimeseriesValues(SourceAttributePath='//OPENXC/OpenXC/EventFrames%5BtestFrame%5D%7CSinusoid',Timestamp=datetime'2012-09-10T13%3A31%3A09Z')"/> 
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/UOM" type="application/atom+xml;type=entry" title="UOM" href="TimeseriesValues(SourceAttributePath='//OPENXC/OpenXC/EventFrames%5BtestFrame%5D%7CSinusoid',Timestamp=datetime'2012-09-10T13%3A31%3A09Z')/UOM"/> 
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SourceAttribute" type="application/atom+xml;type=entry" title="SourceAttribute" href="TimeseriesValues(SourceAttributePath='//OPENXC/OpenXC/EventFrames%5BtestFrame%5D%7CSinusoid',Timestamp=datetime'2012-09-10T13%3A31%3A09Z')/SourceAttribute"/> 
<category term="vCampus.OData.Web.ObjectModel.TimeSeriesValue" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/> 
<content type="application/xml"> 
<m:properties> 
<d:Timestamp m:type="Edm.DateTime">2012-09-10T13:31:09Z</d:Timestamp> 
<d:SourceAttributePath>\\OPENXC\OpenXC\EventFrames[testFrame]|Sinusoid</d:SourceAttributePath> 
<d:Value>85.7081527709961</d:Value> 
<d:UOMName m:null="true"/> 
<d:AdditionalInfo/> 
<d:Annotated m:type="Edm.Boolean">false</d:Annotated> 
<d:IsGood m:type="Edm.Boolean">true</d:IsGood> 
<d:Questionable m:type="Edm.Boolean">false</d:Questionable> 
<d:Status>Good</d:Status> 
<d:Substituted m:type="Edm.Boolean">false</d:Substituted> 
</m:properties> 
</content> 
</entry> 
<entry> 
<id>http://[redacted]/OData/PIDataService.svc/TimeseriesValues(SourceAttributePath='//OPENXC/OpenXC/EventFrames%5BtestFrame%5D%7CSinusoid',Timestamp=datetime'2012-09-10T14%3A40%3A09Z')</id> 
<title type="text"/> 
<updated>2012-09-11T12:09:12Z</updated> 
<author> 
<name/> 
</author> 
<link rel="edit" title="TimeSeriesValue" href="TimeseriesValues(SourceAttributePath='//OPENXC/OpenXC/EventFrames%5BtestFrame%5D%7CSinusoid',Timestamp=datetime'2012-09-10T14%3A40%3A09Z')"/> 
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/UOM" type="application/atom+xml;type=entry" title="UOM" href="TimeseriesValues(SourceAttributePath='//OPENXC/OpenXC/EventFrames%5BtestFrame%5D%7CSinusoid',Timestamp=datetime'2012-09-10T14%3A40%3A09Z')/UOM"/> 
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SourceAttribute" type="application/atom+xml;type=entry" title="SourceAttribute" href="TimeseriesValues(SourceAttributePath='//OPENXC/OpenXC/EventFrames%5BtestFrame%5D%7CSinusoid',Timestamp=datetime'2012-09-10T14%3A40%3A09Z')/SourceAttribute"/> 
<category term="vCampus.OData.Web.ObjectModel.TimeSeriesValue" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/> 
<content type="application/xml"> 
<m:properties> 
<d:Timestamp m:type="Edm.DateTime">2012-09-10T14:40:09Z</d:Timestamp> 
<d:SourceAttributePath>\\OPENXC\OpenXC\EventFrames[testFrame]|Sinusoid</d:SourceAttributePath> 
<d:Value>99.2516555786133</d:Value> 
<d:UOMName m:null="true"/> 
<d:AdditionalInfo/> 
<d:Annotated m:type="Edm.Boolean">false</d:Annotated> 
<d:IsGood m:type="Edm.Boolean">true</d:IsGood> 
<d:Questionable m:type="Edm.Boolean">false</d:Questionable> 
<d:Status>Good</d:Status> 
<d:Substituted m:type="Edm.Boolean">false</d:Substituted> 
</m:properties> 
</content> 
</entry> 
... 

(윈도우 폰) 클라이언트 코드 나에게 적절한 결과를 제공하는 다음의 조작

http://localhost/ODATA/PIDataService.svc/RecordedValues?path='\\OPENXC\OpenXC\EventFrames[testFrame]|Sinusoid'&startTime='*-1d'&endTime='*' 

를 호출 할 필요가

var path = attr.Path; 
        var context = new DatabaseData(new Uri(MainPage.serviceUrl)); 

        var query = context.CreateQuery<TimeSeriesValue>("RecordedValues") 
         .AddQueryOption("path", string.Format("'{0}'", path)) 
         .AddQueryOption("startTime", "'*-1d'") 
         .AddQueryOption("endTime", "'*'"); 
        query.BeginExecute(TimeSeriesReady, query); 


    private void TimeSeriesReady(IAsyncResult result) 
    { 
     var context = result.AsyncState as DataServiceQuery<TimeSeriesValue>; 
     var values = context.EndExecute(result).ToList(); 
     values.ForEach(v => Debug.WriteLine(v.Value)); 
    } 

,691과 'InvalidOperationException이'날 선물

이 요청을 처리하는 중 오류가 발생했습니다.

의 InnerException 메시지가 '0x80000012'와 스택 추적입니다 나는이 오류 코드를 검색 한

at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
     at MS.Internal.XcpImports.WebRequest_Send(InternalWebRequest request) 
     at MS.Internal.InternalWebRequest.Send() 
     at System.Net.Browser.ClientHttpWebRequest.PrepareAndSendRequest(String method, Uri requestUri, Stream requestBodyStream, WebHeaderCollection headerCollection, CookieContainer cookieContainer) 
     at System.Net.Browser.ClientHttpWebRequest.BeginGetResponseImplementation() 
     at System.Net.Browser.ClientHttpWebRequest.InternalBeginGetResponse(AsyncCallback callback, Object state) 
     at System.Net.Browser.ClientHttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state) 
     at System.Data.Services.Http.ClientHttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state) 
     at System.Data.Services.Client.BaseAsyncResult.InvokeAsync(Func`3 asyncAction, AsyncCallback callback, Object state) 
     at System.Data.Services.Client.QueryResult.BeginExecute(DataServiceContext context) 
     at System.Data.Services.Client.DataServiceRequest.BeginExecute(Object source, DataServiceContext context, AsyncCallback callback, Object state) 
     at System.Data.Services.Client.DataServiceQuery`1.BeginExecute(AsyncCallback callback, Object state) 
     at vCampus.OData.Phone.DetailsPage.eventFrames_LoadCompleted(Object sender, LoadCompletedEventArgs e) 
     at System.Data.Services.Client.DataServiceCollection`1.<>c__DisplayClass11.<>c__DisplayClass13.<BeginLoadAsyncOperation>b__f() 
     at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) 
     at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) 
     at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) 
     at System.Delegate.DynamicInvokeOne(Object[] args) 
     at System.MulticastDelegate.DynamicInvokeImpl(Object[] args) 
     at System.Delegate.DynamicInvoke(Object[] args) 
     at System.Windows.Threading.DispatcherOperation.Invoke() 
     at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority) 
     at System.Windows.Threading.Dispatcher.OnInvoke(Object context) 
     at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args) 
     at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args) 
     at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult) 

이지만, 어떤 답을 찾을 수 없습니다. 온라인에서 사용할 수있는 코드 샘플은이 방법을 제안하지만이 오류에 대해서는 설명하지 않습니다. 우리의 DEVS의

var path = attr.Path; 
var context = new DatabaseData(new Uri(MainPage.serviceUrl)); 
var query = context.CreateQuery<TimeSeriesValue>("RecordedValues") 
       .AddQueryOption("path", string.Format("'{0}'", Uri.EscapeUriString(path))) 
       .AddQueryOption("startTime", "'*-1d'") 
       .AddQueryOption("endTime", "'*'"); 
query.BeginExecute(TimeSeriesReady, query); 

하나는 테스트 모두 기존의 윈도우 폰 클라이언트 비트뿐만 아니라 우리 곧 윈도우 폰 클라이언트에 대한 확인 : VITEK 제안으로

+0

오류의 원인을 알지 못합니다. 경로 매개 변수의 백 슬래시가 URL에 적합하지 않다고 생각됩니다. 쿼리 옵션을 설정하기 전에 Uri.EscapeDataString을 사용해보십시오. –

+0

그걸 확인했는데 서비스의 [WebGet] 메소드에서 'path'매개 변수가 올바르게 도착했습니다. 또한 : 동일한 코드가 일반 .NET 콘솔 응용 프로그램에서 작동합니다. Windows Phone 코드에서 문제가되는 것 같습니다. – MvdV

답변

0

Uri.EscapeUriStringpath 쿼리 옵션을 탈출하는 데 사용되어야합니다 비트.

관련 문제