它如何作为WCF服务工作?
public class BusinessObject<T> where T : IEntity
{
public T Entity { get; set; }
public BusinessObject(T entity)
{
this.Entity = entity;
}
}
public interface IEntity { }
public class Student : IEntity
{
public int StudentID { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想公开BusinessObject <T>类以及在WCF服务中继承IEntity接口的所有类.
我的代码在C#,.NET Framework 4.0中,在Visual Studio 2010 Pro中构建.
假设我们有一个我们使用的外部服务器(例如电话站等)。我们还有下一个代码:
try
{
externalService.CreateCall(callParams);
}
catch (Exception ex)
{
_log.Error("Unexpected exception when trying execute an external code.", ex);
_callService.UpdateCallState(call, CallState.Disconnected, CallOutcome.Failed);
throw;
}
Run Code Online (Sandbox Code Playgroud)
理论上UpdateCallState可以抛出,但我们会使用该代码隐藏这个异常,并且只处理CreateCall以正确方式生成的异常。
问题是,对于这些情况,正确的模式是什么,以便我们正确对待所有异常?
我现在在我的项目中单独使用asio,它应该被构建为其他人使用的共享库。
但我收到以下错误:
warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately.
Run Code Online (Sandbox Code Playgroud)
我的问题是,我可以在我的.pro文件中添加一个宏定义来避免它。
有人能告诉我怎么做吗,就像添加一样
#define PI 3.1415926
Run Code Online (Sandbox Code Playgroud)
到.pro文件。
使用绝对文件名(例如C:/tinkiwinki/dipsy.lala)使用System.Drawing.Image.Save(Stream, ImageCodecInfo, EncoderParameters)IIS中托管的WCF服务中的方法在服务器中保存图像时,它不会保存图像,甚至不会抛出异常.
我们有一个帮助器类,它有一个SaveJpeg方法:
public class Tools
{
public static void SaveJpeg(string path, Image img, int quality)
{
if (quality < 0 || quality > 100)
throw new ArgumentOutOfRangeException("Quality must be between 0 and 100.");
EncoderParameter qualityParam =
new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;
img.Save(path, jpegCodec, encoderParams);
}
}
Run Code Online (Sandbox Code Playgroud)
我们在这样的WCF OperationContract方法中使用它:
string destDirectory = ServerDataFilePath.ImagesPath + @"\" + uploadID.ToString();
if …Run Code Online (Sandbox Code Playgroud)