2009-09-09 2 views
0

프로젝트 설정이 있습니다. ASP.Net 사이트에서 호스팅되는 Silverlight 클라이언트 응용 프로그램입니다. ADO.Net Entity Framework는 SQL Server 데이터베이스 및 통신을위한 ADO.Net 데이터 서비스와 통신합니다. 내 데이터베이스에서 작동하도록 비동기 CRUD Silverlight 삽입을 가져 오는 데 문제가 있습니다. 첫 번째 메소드는 잘 작동하여 URI를 전달합니다. 그러나 "OnClientJobQueryComplete"메서드가 실행되면 약 5 줄의 줄이 끊어지며 이유를 이해할 수 없습니다. 예외는 "이 요청을 처리하는 동안 오류가 발생했습니다."라고 말합니다. Silverlight - Crud Insert가 예기치 않게 실패 했습니까?

private void addStuff_Click(object sender, RoutedEventArgs e) 
    { 
     // Define a URI that returns the product with the specified ID. 
     Uri jobrefUri = new Uri(svcContext.BaseUri.AbsoluteUri 
      + "/ClientJob(" + this.jobref.Text + ")"); 

     // Begin a query operation retrieve the Product object 
     // that is required to add a link to the new Order_Detail. 
     svcContext.BeginExecute<ClientJob>(jobrefUri, 
      OnClientJobQueryCompleted,null); 
    } 

    private void OnClientJobQueryCompleted(IAsyncResult result) 
    { 
     // Use the Dispatcher to ensure that the 
     // asynchronous call returns in the correct thread. 
     Dispatcher.BeginInvoke(() => 
     { 
      // Get the Product returned by the completed query. 
      IEnumerable<ClientJob> queryResult = 
       svcContext.EndExecute<ClientJob>(result);//**TRIES THIS BUT FAILS HERE 

      ClientJob returnedClientJob = queryResult.First(); 

      // Get the currently selected order. (Create new Guid since not Northwind) 
      Guid g = Guid.NewGuid(); 

      // Create a new Order_Details object with the supplied FK values. 
      Job newItem = Job.CreateJob(g); 
      //Job newItem = Job.CreateJob(g, returnedClientJob.JobRef); 

      jobsBindingCollection.Add(newItem); 

      // Add the new item to the context. 
      svcContext.AddToJob(newItem); 

      //// Add the relationship between the order and the new item. 
      //currentOrder.Order_Details.Add(newItem); 
      //svcContext.AddLink(currentOrder, "Order_Details", newItem); 

      //// Set the reference to the order and product from the item. 
      //newItem.Orders = currentOrder; 
      //svcContext.SetLink(newItem, "Orders", currentOrder); 

      // Add the relationship between the product and the new item. 
      returnedClientJob.Job.Add(newItem); 
      svcContext.AddLink(returnedClientJob, "Job", newItem); 

      // Set the reference to the product from the item. 
      newItem.ClientJob = returnedClientJob; 
      svcContext.SetLink(newItem, "ClientJob", returnedClientJob); 
     } 
     ); 
    } 

이 코드

은 해제하고 Northwind 데이터베이스를 사용 this 마이크로 소프트 튜토리얼에서 수정됩니다. 튜토리얼의 다른 코드 샘플은 모두 데이터베이스가 Northwind와 비슷한 구조이므로 잘 작동합니다. 지금까지 RUD를 구현할 수 있었지만 CRUD는 구현할 수 없었습니다.

피사체를 밝힐 사람이 있습니까?

대단히 감사합니다.

답변

1

엔티티 액세스 권한이 필요할 수 있습니다. 자습서의 one of the steps에이 글이 구성되어 있지만 일부 경우에는 "AllRead"로 설정되어 있습니다. 엔티티가 쓰기 액세스를 허용하는지 확인해야합니다.

+0

이 하나가 이미 두려워 메신저 봤어, – Goober

0

바로 지금 문제가 어디에서 발생하는지 정확하게 알 수없는 많은 레이어가 있습니다.

Windows 응용 프로그램에서 EF 모델로 직접 쿼리를 호출해도 작동합니까? 그렇지 않은 경우 모델에 문제가있는 것 같습니다.

브라우저에서 ADO.NET 데이터 서비스에 액세스 할 수 있습니까?

서비스를 호스팅하는 서버에 clientaccesspolicy.xml 파일이 있습니까?

당신은 http : // 위치에서 실버 라이트 앱을 실행 하나 file : // 위치에서 실행하지 않습니까?

+0

:-(차이가 나는 약간의 성공을 거두었하게하지 않는 것 -이 줄을 변경 한 : + "/ ClientJob 열린 jobrefUri = 새로운 열린 우리당 (svcContext.BaseUri.AbsoluteUri 을 ("+ this.jobref.Text +") ")"); to Uri jobrefUri = new Uri (svcContext.BaseUri.AbsoluteUri + "/ ClientJob (" "+ this.jobref.Text +" ') ") 당신은 함께 검색 할 값을 캡슐화하는 작은 따옴표가 포함되어 있다는 것을 알 수 있습니다. 그러나 이것이 올바르게 작동하는지는 모르지만 이것이 올바른 구현인지는 확실하지 않습니다 .... – Goober

관련 문제