2011-11-26 4 views
1

이것은 데이터베이스에 실버 라이트로 이미지를 저장하는 데있어서 다시 한 번 문제가 될 수 있습니다. 다른 이미지로 시도 할 때까지 모든 작업을 수행 할 수 있다고 생각했습니다 ...이미지를 데이터베이스에 varbinary로 저장 (파트 3)

다음 방법으로 데이터베이스에 이미지를 저장합니다. 먼저 이미지를 byte의 배열로 변환 한 다음 내 서비스로 보냅니다.

private void btnUpload_Click(object sender, RoutedEventArgs e) 
     { 
      //nieuwe instantie van de klasse "Afbeelding", om later door te sturen naar service 
      Afbeelding a = new Afbeelding(); 

      OpenFileDialog openFileDialog = new OpenFileDialog(); 
      openFileDialog.Filter = "JPEG files|*.jpg"; 

      if (openFileDialog.ShowDialog() == true) 
      { 
       //Afbeelding ophalen via open dialoog 
       Stream stream = (Stream)openFileDialog.File.OpenRead(); 
       string fileName = openFileDialog.File.Name; 

       //Converteren naar bytes 
       //byte[] bytes = BinaryConverter.convertToByte(stream); 
       byte[] bytes = new byte[stream.Length]; 
       stream.Read(bytes, 0, (int)stream.Length); 

       //aan de instantie de Binary waarde van de afbeelding meegeven om naar de database te sturen 
       a.id = 1; 
       a.source = new Binary { Bytes = bytes }; 
      } 

      EditAfbeeldingServiceClient client = new EditAfbeeldingServiceClient(); 

      client.UpdateAfbeeldingCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(client_UpdateAfbeeldingCompleted); 
      client.UpdateAfbeeldingAsync(a); 
     } 

그리고 내 서비스에서 나는이 작업을 수행 :

내가 함께 지금 바로 시도 그래서
[OperationContract] 
    public void UpdateAfbeelding(Afbeelding a) 
    { 
     var query = (from p in dc.Afbeeldings 
        where p.id == a.id 
        select p).SingleOrDefault(); 

     query.source = a.source; 
     dc.SubmitChanges(); 

    } 
이 모든 일을 테스팅을 내 동안 지금

,하지만 난 단지 테스트하는 하나 개의 이미지를 사용 ... 내가 여기에 붙어있어, 그래서 다시 한 번

System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (400) Bad Request. In Silverlight, a 404 response code may be reported even when the service sends a different error code. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. 
    at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 
    at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState) 
    at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState) 
    --- End of inner exception stack trace --- 
    at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) 
    at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) 
    --- End of inner exception stack trace --- 
    at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result) 
    at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) 
    at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result) 
    at OndernemersAward.EditAfbeeldingServiceReference.EditAfbeeldingServiceClient.EditAfbeeldingServiceClientChannel.EndUpdateAfbeelding(IAsyncResult result) 
    at OndernemersAward.EditAfbeeldingServiceReference.EditAfbeeldingServiceClient.OndernemersAward.EditAfbeeldingServiceReference.EditAfbeeldingService.EndUpdateAfbeelding(IAsyncResult result) 
    at OndernemersAward.EditAfbeeldingServiceReference.EditAfbeeldingServiceClient.OnEndUpdateAfbeelding(IAsyncResult result) 
    at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result) 

난 정말 그 오류에서 아무것도 읽을 수 없습니다 : 다른 이미지는, 나는 다음과 같은 오류가 발생합니다. 이 보드를 너무 많이 사용하는 것에 대해 사과드립니다.하지만별로 필요하지 않은 경우에는 실제로 사용하지 않을 것입니다.

높은 숫자로 보내려면 최대를 설정했지만 여전히 작동하지 않습니다.

<readerQuotas maxDepth="32" 
maxStringContentLength="2147483647" 
maxArrayLength="2147483647" 
maxBytesPerRead="2147483647" 
maxNameTableCharCount="2147483647" /> 

당신은 여기 내 Web.config의를 찾을 수 있습니다

http://pastebin.com/whMs5h1w는 당신의 도움을 주셔서 감사합니다, 정말 감사합니다. 토마스

편집 : 나는, 추적을 가능하게하여보다 읽기 쉬운 오류 관리이 사람 :)

답변

1

WCF가 내장 된 다양한 한계가 도움이되기를 바랍니다 하나는 기본 다른 하나 65536 바이트입니다 maxReceivedMessageSize이다. maxArrayLength (기본값은 확실하지 않음)입니다. 두 가지 중 하나 (또는 ​​두 가지 모두) 중 하나를 초과했을 가능성이 큽니다. 서비스 구성에서 변경 될 수 있습니다. This article on MSDN에는 몇 가지 구성 예제가 포함되어 있습니다.

enabling tracing for your service 또한 어떤 제한에 도달했는지에 대한 통찰력을 제공 할 수 있습니다.

Btw : File.ReadAllBytes 방법이 있습니다.

편집 : 분명히 이러한 문제를 추적하는 데 도움이 할 수있는 Fiddler라는 도구가있다.

+0

그럼 어떻게해야합니까? WCF로 내 데이터베이스에 이미지를 저장할 수 없습니까? – Schoof

+0

@ThomasSchoof : 아니요, 설정에서 제한을 늘려야합니다. 죄송합니다. 답을 더 명확하게 표시했습니다. – ChrisWue

+0

나는 이전 오류 때문에 maxArrayLength를 이미 늘려야 만했다. 그리고 나는 그것을 늘려야한다고 말했다. (http://stackoverflow.com/questions/8275398/saving-image-to-database-as-varbinary-arraylength-part-2/8275697#8275697) 그리고 난 그냥 File.ReadAllbytes 메서드를 사용하여 바이트 배열에 이미지? – Schoof

관련 문제