【问题标题】:Sending Image file data from C# windows application to WCF service将图像文件数据从 C# windows 应用程序发送到 WCF 服务
【发布时间】:2016-11-24 14:11:10
【问题描述】:

我正在开发一个 C# windows 应用程序并尝试将图像文件的字节 [] 发送到 WCF 服务。下面是我在 windows 应用程序中的代码。

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[] 数据,或者有没有其他方法可以实现。

我看到了很多 atricles,但我找不到任何可以将图像数据发送到 WCF 服务的工作示例。让我知道,如果有人做过这方面的工作。

谢谢。

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    使用以下示例方法接收字节

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

    【讨论】:

    • 感谢回复,“UploadData”是“WebClient”对象的一个​​方法。但我期待“SaveVisitorPhoto”方法中的 byte[] 数据。
    • 我尝试在 WebClient 标头中将内容作为 base64 字符串传递。但是我收到了错误的请求错误。我在“绑定”部分下的配置文件中设置了 maxStringContentLength="2147483647"。没运气。但是,如果我不传递 base64 字符串数据,我可以在 WCF 服务端成功获取其他标头值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    相关资源
    最近更新 更多