WCF内URL格式化的问题
我建立了一个WEB WCF服务(在MVC的网站里面), 然后取得的数据里面的图片地址都是~/images/1.jpg, ~/images/2.jpg所以在输出json的时候必须先要把这些URL格式化然后再输出.
在MVC的Controller里面可以直接用UrlHelper.Content(addr); 就好了.
但在WCF里面没办法用UrlHelper.Content, 它需要传一个HttpContextBase参数, 不知道如何弄.
这个HttpContextBase和HttpContext不一样.
如果是HttpContext的话能打开asp.net兼容然后使用. 但是这个HttpContextBase就不知道要怎么取得了.
或者有其它办法能格式化这个图片地址吗? wcf mvc urlhelper wcf mvc urlhelper httpcontextbase --------------------编程问答-------------------- 已解决!
public class MvcHttpContextService
{
private HttpContextBase _ServiceContext;
public HttpContextBase ServiceContext
{
get
{
if (_ServiceContext == null)
_ServiceContext = new HttpContextWrapper(HttpContext.Current);
return _ServiceContext;
}
set { _ServiceContext = value; }
}
}
哪个服务要用, 继承这个类就行了, 就是HttpContextWrapper这个类, 当然了, 必须为WCF打开asp.net兼容模式.
原文地址: http://stackoverflow.com/questions/12050017/using-httpcontextbase-in-service-layer
但他问的问题不是我这个. --------------------编程问答-------------------- 感谢lz分享解决方案。 --------------------编程问答--------------------
好幸福的头像!!!!! --------------------编程问答-------------------- 感谢分享------ --------------------编程问答-------------------- 路过留名
补充:.NET技术 , Web Services