Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 接收图像的WCF服务_.net_Wcf_Web Services_Image - Fatal编程技术网

.net 接收图像的WCF服务

.net 接收图像的WCF服务,.net,wcf,web-services,image,.net,Wcf,Web Services,Image,创建接受图像的Web服务的最佳方式是什么。 图像可能很大,我不想更改web应用程序的默认接收大小。 我写了一个接受二进制图像的,但我觉得必须有更好的选择。这个图像在哪里?它可以在本地文件系统或web上访问吗?如果是这样,我建议让您的Web服务接受URI,可以是URL或本地文件,并将其作为流打开,然后使用StreamReader读取其内容 示例,但将异常包装在FaultExceptions中,并添加FaultContractAttribute: using System.Drawing; usin

创建接受图像的Web服务的最佳方式是什么。 图像可能很大,我不想更改web应用程序的默认接收大小。
我写了一个接受二进制图像的,但我觉得必须有更好的选择。

这个图像在哪里?它可以在本地文件系统或web上访问吗?如果是这样,我建议让您的Web服务接受URI,可以是URL或本地文件,并将其作为流打开,然后使用StreamReader读取其内容

示例,但将异常包装在FaultExceptions中,并添加FaultContractAttribute:

using System.Drawing;
using System.IO;
using System.Net;
using System.Net.Sockets;

[OperationContract]
public void FetchImage(Uri url)
{
    // Validate url

    if (url == null)
    {
        throw new ArgumentNullException(url);
    }

    // If the service doesn't know how to resolve relative URI paths

    /*if (!uri.IsAbsoluteUri)
    {
        throw new ArgumentException("Must be absolute.", url);
    }*/

    // Download and load the image

    Image image = new Func<Bitmap>(() =>
    {
        try
        {
            using (WebClient downloader = new WebClient())
            {
                return new Bitmap(downloader.OpenRead(url));
            }
        }
        catch (ArgumentException exception)
        {
            throw new ResourceNotImageException(url, exception);
        }
        catch (WebException exception)
        {
            throw new ImageDownloadFailedException(url, exception);
        }

        // IOException and SocketException are not wrapped by WebException :(            

        catch (IOException exception)
        {
            throw new ImageDownloadFailedException(url, exception);
        }
        catch (SocketException exception)
        {
            throw new ImageDownloadFailedException(url, exception);
        }
    })();

    // Do something with image

}

这张照片住在哪里?它可以在本地文件系统或web上访问吗?如果是这样,我建议让您的Web服务接受URI,可以是URL或本地文件,并将其作为流打开,然后使用StreamReader读取其内容

示例,但将异常包装在FaultExceptions中,并添加FaultContractAttribute:

using System.Drawing;
using System.IO;
using System.Net;
using System.Net.Sockets;

[OperationContract]
public void FetchImage(Uri url)
{
    // Validate url

    if (url == null)
    {
        throw new ArgumentNullException(url);
    }

    // If the service doesn't know how to resolve relative URI paths

    /*if (!uri.IsAbsoluteUri)
    {
        throw new ArgumentException("Must be absolute.", url);
    }*/

    // Download and load the image

    Image image = new Func<Bitmap>(() =>
    {
        try
        {
            using (WebClient downloader = new WebClient())
            {
                return new Bitmap(downloader.OpenRead(url));
            }
        }
        catch (ArgumentException exception)
        {
            throw new ResourceNotImageException(url, exception);
        }
        catch (WebException exception)
        {
            throw new ImageDownloadFailedException(url, exception);
        }

        // IOException and SocketException are not wrapped by WebException :(            

        catch (IOException exception)
        {
            throw new ImageDownloadFailedException(url, exception);
        }
        catch (SocketException exception)
        {
            throw new ImageDownloadFailedException(url, exception);
        }
    })();

    // Do something with image

}

难道你不能使用FTP将图像上传到服务器上吗?然后,当上传完成后,服务器和WCF服务车就可以轻松地访问它了?这样,您就不需要考虑接收大小设置等


至少,我是这样做的。

难道你不能使用FTP将图像上传到服务器上,然后在上传完成后,服务器就可以轻松访问,从而WCF服务车也可以轻松访问它吗?这样,您就不需要考虑接收大小设置等


至少,我是这样做的。

映像驻留在客户端,Web服务器无法通过uri获取映像。映像驻留在客户端,Web服务器无法通过uri获取映像。