我正在测试一些WCF服务,它们来回传送带有Guids的对象.在我的网络应用程序测试代码中,我正在执行以下操作:
var responseObject = proxy.CallService(new RequestObject
{
Data = "misc. data",
Guid = new Guid()
});
Run Code Online (Sandbox Code Playgroud)
出于某种原因,对新Guid()的调用是生成Guids,其全部为0(零),如下所示:
00000000-0000-0000-0000-000000000000
可能是什么导致了这个?
我有一个带有几个ConnectionStrings的Web.config
<connectionStrings>
<add name="connStr1" connectionString="...
<add name="ConnStr2" connectionString="...
<add name="connStr3" connectionString="...
Run Code Online (Sandbox Code Playgroud)
有没有办法使用配置转换来删除特定的连接字符串?就像是:
<connectionStrings>
<xdt:Remove connStr2?
Run Code Online (Sandbox Code Playgroud)
显然没有接近正确的语法,但你得到我的漂移...
IntelliSense告诉我"Expression不能包含匿名方法或lambda表达式".真?我不知道这个强加的限制.它是否正确?我想我正在寻找一个健全检查......
public delegate bool Bar(string s);
[AttributeUsage(AttributeTargets.All)]
public class Foo : Attribute
{
public readonly Bar bar;
public Foo(Bar bar)
{
this.bar = bar;
}
}
public class Usage
{
[Foo(b => b == "Hello World!")] // IntelliSense Complains here
public Usage()
{
}
}
Run Code Online (Sandbox Code Playgroud) 所以我决定在我的WCF应用程序中提高性能,并尝试缓存Channels和ChannelFactory.关于所有这些我有两个问题需要在开始之前清理.
1)ChannelFactory应该实现为单例吗?
2)我不确定如何缓存/重用各个频道.你有任何关于如何分享的例子吗?
值得注意的是,我的WCF服务被部署为独立应用程序,只有一个端点.
编辑:
感谢您的回复.我还有几个问题......
1)我想我对缓存应该发生的位置感到困惑.我正在提供一个客户端API,它将此代码用于我们公司的另一个部门.这个缓存是否发生在客户端?
2)客户端API将用作Silverlight应用程序的一部分,这会改变什么吗?特别是,在这种情况下可以使用哪些缓存机制?
3)我还不清楚GetChannelFactory方法的设计.如果我只有一个服务,是否应该只创建和缓存一个ChannelFactory?
我还没有实现任何缓存功能(因为我对如何完成它完全感到困惑!),但这是我到目前为止客户端代理所拥有的:
namespace MyCompany.MyProject.Proxies
{
static readonly ChannelFactory<IMyService> channelFactory =
new ChannelFactory<IMyService>("IMyService");
public Response DoSomething(Request request)
{
var channel = channelFactory.CreateChannel();
try
{
Response response = channel.DoSomethingWithService(request);
((ICommunicationObject)channel).Close();
return response;
}
catch(Exception exception)
{
((ICommenicationObject)channel).Abort();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图在WCF服务实现中使用IDispatchMessageInspector来访问自定义标头值.
就像是:
public class MyService : IMyService
{
public List<string> GetNames()
{
var headerInspector = new CustomHeaderInspector();
// Where do request & client channel come from?
var values = headerInspector.AfterReceiveRequest(ref request, clientChannel, OperationContext.Current.InstanceContext);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经实现了自己的IDispatchMessageInspector类.
public class CustomHeaderInspector : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
var prop = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
var userName = prop.Headers["Username"];
return userName;
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么通过
System.ServiceModel.Channels.消息和
System.ServiceModel.IClientChannel
到AfterReceiveRequest叫服务实现?
编辑:
很多像这样或者 …
所以"幂等"可以定义为:
如果执行N次的动作与仅执行一次动作具有相同的效果.
明白了,很容易.
我的问题是关于这个定义的微妙之处 - 这个行为本身就被认为是幂等的,还是你还必须考虑传递给行动的数据?
让我用一个例子来澄清:
假设我有一个更新某些资源的PUT方法,我们称之为 f(x)
显然,f(3)只要我提供3作为输入,就是幂等的.同样显而易见的是,f(5)将改变资源的价值(即,它将不再是3或以前的任何值)
所以当我们谈论幂等性时,我们是指动作/函数的概括(如,f(x)),还是我们指的是动作/函数+传递给它的数据(即f(3))?
假设我在局部视图中有一个javascript幻灯片放映...
_Slideshow.cshtml:
@{
ViewBag.Title = "Slide Show";
}
<div id="slides">
</div>
<script src="js/slides.min.jquery.js"></script>
<script type="text/javascript">
$(function(){
$('#slides').slides({
// slide show configuration...
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
但我想成为一名优秀的小型Web开发人员,并确保我的所有脚本都位于页面底部.所以我会让我的*_Layout.cshtml*页面看起来像这样:
_Layout.cshtml:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/css/global.css")" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
@RenderBody
</div>
<!-- Being a good little web developer, I include my scripts at the BOTTOM, yay!
-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是UH OH!我现在该怎么做,因为我的幻灯片脚本最终超出了我的jQuery包含范围?!如果我想在每个页面上播放幻灯片,这不会是什么大不了的事,但我只希望幻灯片放映部分视图在某个页面上呈现,并且......我希望我的脚本在底部!该怎么办?
我是Team Foundation Server的新手,我目前正在为我的项目设置自动构建策略.我遇到的一点困惑是如何设置与我们的源代码控制/开发结构相匹配的自动构建.
公司政策是在TFS项目下,我们包括文件夹'trunk'和'branches'.'Trunk'代表并包含我们的生产代码."分支机构"显然正在开发分支机构.
我想为分支机构设置CI(持续集成)构建,并为'trunk'设置'Gated check-in'构建.我的想法是,当它需要推出生产时,这几乎可以消除"主干"构建的任何问题.但是我对这一切有一些问题:
1.我的策略有意义吗?(它是否过于冗余?是否会产生无法预料的问题?等)
2."合并"是否构成触发CI或Gated构建的"签到"?如果开发人员将他们的开发分支合并到'trunk',我希望这会触发trunk构建.(也许这里的'Gated'构建是不必要的冗余?)
我们非常感谢您给我的任何指导.先感谢您!
(开发环境:TFS 2010,VS 2010 Ultimate,Windows Server 2008 R2)
是的SaveChanges()必要的功能,进口(存储过程)?
例:
void foo(Product product)
{
// AddProduct is a function import of a stored procedure
entities.AddProduct(product.Name, product.Price, product.Description);
entities.SaveChanges(); // Is this necessary?
}
Run Code Online (Sandbox Code Playgroud) .net c# stored-procedures entity-framework entity-framework-4
这篇MSDN文章说:
HttpContext: Current is always null when accessed from within a WCF service. Use RequestContext instead.
我要做的是从我的IIS托管WCF服务加载一些XSD文件.问题是,我无法弄清楚如何在任何旧的vanilla ASP.NET网站中执行Server.MapPath(),例如:
HttpContext.Current.Server.MapPath(schemaUri);
在IIS托管的WCF服务中使用RequestContext的等效方法是什么?
模式位于服务应用程序根目录下的"模式"目录中.它们是使用web.config中的自定义配置部分引用的,如下所示:
<schemas>
<add uri="~/Schemas/foo.xsd" xmlNamespace="http://foo.bar/types" />
</schemas>
Run Code Online (Sandbox Code Playgroud)
我试图像这样加载:
var schemaUri = HttpContext.Current.Server.MapPath(schema.Uri);
从普通的ASP.NET网站中可以正常工作,而不是IIS托管的WCF服务.
c# ×9
.net ×8
wcf ×4
web-services ×2
asp.net ×1
asp.net-mvc ×1
attributes ×1
channel ×1
guid ×1
http ×1
http-verbs ×1
idempotent ×1
javascript ×1
lambda ×1
rest ×1
team-build ×1
tfs ×1
web-config ×1
xsd ×1