2016-11-23 74 views
0

我正在研究C#windows應用程序並嘗試將圖像文件的byte []發送到WCF服務。以下是我在windows應用程序中的代碼。將圖像文件數據從C#windows應用程序發送到WCF服務

private bool SaveVisitorPhoto() 
{ 
byte[] visitorPhotoByte; 
using (WebClient webClient = new WebClient()) 
{ 

    visitorPhotoByte = ImageUtility.ImageToByte(picVisitorPhoto.Image, ImageFormat.Png); 
    string url = webServiceURL + "SaveVisitorPhoto/" + VisitPIN; 
    webClient.UploadData(url, visitorPhotoByte); 
    return true; 
}} 

[OperationContract] 
[WebInvoke(UriTemplate = "SaveVisitorPhoto/{visitPIN}", ResponseFormat = WebMessageFormat.Json)]bool SaveVisitorPhoto(string visitPIN); 

現在我不知道如何獲取WCF服務中的byte []數據,或者是否有任何其他方式來實現此目的。

我看到了很多廣告,但是我找不到任何有用的示例將圖片數據發送到WCF服務。讓我知道,如果有人已經爲此工作。

謝謝。

回答

0

使用下面的示例方法來接收字節

public void UploadData(string URL,byte[] byteArrayIn) 
    { 
     ---------- 
    } 
+0

感謝您的答覆「 UploadData」是「Web客戶端」對象的方法。但我期待「SaveVisitorPhoto」方法中的byte []數據。 – user1396423

+0

我試圖在WebClient頭文件中以base64字符串的形式傳遞內容。但我得到錯誤的請求錯誤。我在配置文件的「綁定」一節中設置了maxStringContentLength =「2147483647」。沒有運氣。但是,如果我不傳遞base64字符串數據,我能夠在WCF服務端成功獲取其他頭值。 – user1396423

相關問題