0

私がやろうとしていることは…</p>

ユーザーが WCF を使用して PDF ファイルとその他のファイルを選択できるようにします...ファイルを選択したら、それらのファイルをそこからリモート サーバー (会社がホストする) に移動する必要があります。データを逆シリアル化し(バイトとして読み取り)、転送しようとしています。テスト目的として、またクライアントがどのように動作するかを確認するためにフォームを作成しました。

ファイルを取得すると....ファイルを表示できますが、実際のP​​DFを取得したいのですが、それができません。ファイルをメモ帳で開くことができますが (バイト形式です)、PDF で開こうとすると、ファイル形式がサポートされていないと表示されます。私は本当に混乱していて、何をする必要があるのか​​ わかりません。

あなたの助けは本当に感謝されます.

Code Snippet:

クライアント側:

    private void btnUploadFile_Click(object sender, EventArgs e)
            {
            string pathServer = @"C:\Users\....\Desktop\Test.pdf";

            RestClient newClient = new      RestClient("http://localhost:...../Service1.svc/DisplayRawData");
            var request = new RestRequest(Method.GET);
            request.RequestFormat = DataFormat.Json;
            request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
            IRestResponse<TempString> newResponse = newClient.Execute<TempString>(request);
            //List<TempString> rtrn = (List<TempString>)newResponse.Data;     
            var responseData = newClient.DownloadData(request);

            FileStream fStream = new FileStream(pathServer, FileMode.Create);

            BinaryWriter bw = new BinaryWriter(fStream);

            bw.Write(responseData);
            bw.Close();

            foreach (var xbyte in responseData)
            {
               // fStream.WriteByte(xbyte); 

            }

            //fStream.Flush();
            fStream.Close(); 

Server Side (Service)

public string DisplayRawData()
        {
            string path = @"C:\basketball.pdf";
            byte[] fileToSend = File.ReadAllBytes(path);
            string filetoSendB64 = Convert.ToBase64String(fileToSend);
           // WebOperationContext.Current.OutgoingResponse.ContentType = "application/pdf";

            return filetoSendB64;
        }

Interface

        //Getting Stream from a File
        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "DisplayRawData",
                    RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]

        // string DisplayRawData();

        string DisplayRawData();
4

1 に答える 1