我无法理解这个错误的底部,因为当附加调试器时,它似乎不会发生.下面是代码.
这是Windows服务中的WCF服务器.每当存在数据事件时,服务就会调用NotifySubscribers方法(以随机间隔,但不常见 - 每天约800次).
当Windows窗体客户端订阅时,订户ID将添加到订阅者字典中,当客户端取消订阅时,将从字典中删除它.客户端取消订阅时(或之后)发生错误.看来,下次调用NotifySubscribers()方法时,foreach()循环失败并显示主题行中的错误.该方法将错误写入应用程序日志,如下面的代码所示.当附加调试器并且客户端取消订阅时,代码执行正常.
你看到这段代码有问题吗?我是否需要使字典线程安全?
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class SubscriptionServer : ISubscriptionServer
{
private static IDictionary<Guid, Subscriber> subscribers;
public SubscriptionServer()
{
subscribers = new Dictionary<Guid, Subscriber>();
}
public void NotifySubscribers(DataRecord sr)
{
foreach(Subscriber s in subscribers.Values)
{
try
{
s.Callback.SignalData(sr);
}
catch (Exception e)
{
DCS.WriteToApplicationLog(e.Message,
System.Diagnostics.EventLogEntryType.Error);
UnsubscribeEvent(s.ClientId);
}
}
}
public Guid SubscribeEvent(string clientDescription)
{
Subscriber subscriber = new Subscriber();
subscriber.Callback = OperationContext.Current.
GetCallbackChannel<IDCSCallback>();
subscribers.Add(subscriber.ClientId, subscriber);
return subscriber.ClientId;
}
public void UnsubscribeEvent(Guid clientId)
{
try
{
subscribers.Remove(clientId);
}
catch(Exception …
Run Code Online (Sandbox Code Playgroud) 在设计REST API或服务时,是否存在处理安全性(身份验证,授权,身份管理)的最佳实践?
构建SOAP API时,您需要使用WS-Security作为指南,并且有很多关于该主题的文献.我发现有关保护REST端点的信息较少.
虽然我理解REST故意没有规格类似于WS-*我希望最佳做法或建议的模式已经出现.
任何讨论或相关文件的链接将非常感谢.如果它的事项,我们将使用WCF与我们的REST API的/服务POX/JSON序列信息使用.NET Framework V3.5的建立.
我花了几个月的时间试图掌握WCF背后的概念,最近我开发了我的第一个WCF服务应用程序.
我很难理解配置文件中的所有设置.
我不相信环境,但似乎你可以用它做出惊人的东西.
前几天我发现微软已经推出了一款名为ASP.NET Web API的新产品.
我可以阅读它是一个RESTful框架,非常易于使用和实现.
现在,我试图找出2个框架之间的主要区别,以及是否应该尝试使用新API 转换旧的 WCF服务应用程序.
有人可以帮我理解每个的差异和用法吗?
我有一个WCF服务,它从数据库返回1000条记录到客户端.我有一个ASP.NET WCF客户端(我在asp.net Web应用程序项目中添加了服务引用以使用WCF).
运行客户端应用程序时收到以下消息:
已超出传入邮件的最大邮件大小限额(65536).要增加配额,请在相应的绑定元素上使用MaxReceivedMessageSize属性.
有帮助吗?如何增加邮件大小配额?
我有一个WCF服务,我想将它作为RESTfull服务和SOAP服务公开.以前有人做过这样的事吗?
我喜欢在using
块中实例化我的WCF服务客户端,因为它几乎是使用实现的资源的标准方法IDisposable
:
using (var client = new SomeWCFServiceClient())
{
//Do something with the client
}
Run Code Online (Sandbox Code Playgroud)
但是,正如本MSDN文章中所述,在using
块中包装WCF客户端可能会掩盖导致客户端处于故障状态的任何错误(如超时或通信问题).简而言之,当调用Dispose()时,客户端的Close()方法会触发,但会因为处于故障状态而抛出错误.然后,第二个异常掩盖了原始异常.不好.
MSDN文章中建议的解决方法是完全避免使用using
块,而是实例化您的客户端并使用它们,如下所示:
try
{
...
client.Close();
}
catch (CommunicationException e)
{
...
client.Abort();
}
catch (TimeoutException e)
{
...
client.Abort();
}
catch (Exception e)
{
...
client.Abort();
throw;
}
Run Code Online (Sandbox Code Playgroud)
与using
块相比,我认为这很难看.每次需要客户端时都需要编写很多代码.
幸运的是,我发现了一些其他的解决方法,例如IServiceOriented上的这个.你从:
public delegate void UseServiceDelegate<T>(T proxy);
public static class Service<T>
{
public static ChannelFactory<T> _channelFactory = new ChannelFactory<T>("");
public static void Use(UseServiceDelegate<T> codeBlock)
{ …
Run Code Online (Sandbox Code Playgroud) 我对WCF和ASMX Web服务感到困惑.我在早期阶段使用了很多Web服务,现在引入了一个名为WCF的新东西.我仍然可以创建作为Web服务的WCF.我认为WCF会有更多东西.
WCF和Web服务之间有什么区别?什么时候应该使用?
我已经为web服务添加了代理到VS2008/.NET 3.5解决方案.构建客户端.NET时抛出此错误:
无法在ServiceModel客户端配置部分中找到引用合同"IMySOAPWebService"的默认端点元素.这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素.
搜索此错误告诉我在合同中使用完整的命名空间.这是我的带有完整命名空间的app.config:
<client>
<endpoint address="http://192.168.100.87:7001/soap/IMySOAPWebService"
binding="basicHttpBinding" bindingConfiguration="IMySOAPWebServicebinding"
contract="Fusion.DataExchange.Workflows.IMySOAPWebService" name="IMySOAPWebServicePort" />
</client>
Run Code Online (Sandbox Code Playgroud)
我正在运行XP本地(我之所以提到这是因为一些谷歌点击提到win2k3)app.config被复制到app.exe.config,所以这也不是问题.
有线索吗?
好的,我有:
Visual Studio 2010 RC,W7 x64,启动了一个新的项目类型的Silverlight应用程序.在ASP.NET Web应用程序项目中托管Silverlight应用程序.Silverlight版本3.0.添加了LinqToSQL类,WCF服务,Winform Tester应用程序(解决方案中的项目)和一些类(也作为解决方案中的项目).
昨天,我突然得到了'断点不会被击中.此文档未加载任何符号.消息出现在IDE中,但它只影响Web Appliaction,我可以调试Silverlight和Winform App.
我尝试/做了什么来消除这个消息:
所以,这发生在我生命中的第二次.上次我通过删除临时ASP.NET文件夹解决了它,但这次我需要你的帮助.
我试图通过basicHttpBinding创建一个WCF服务,以便在https上使用.这是我的web.config:
<!-- language: xml -->
<service behaviorConfiguration="MyServices.PingResultServiceBehavior"
name="MyServices.PingResultService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="defaultBasicHttpBinding"
contract="MyServices.IPingResultService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
...
Run Code Online (Sandbox Code Playgroud)
<bindings>
<basicHttpBinding>
<binding name="defaultBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
...
<behaviors>
<serviceBehaviors>
<behavior name="MyServices.UpdateServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)
我正在使用能够正确检索所有元数据的WCFStorm进行连接,但是当我调用实际方法时,我得到:
提供的URI方案"https"无效; 预计'http'.参数名称:via
wcf ×10
c# ×5
.net-3.5 ×2
asp.net ×2
rest ×2
.net ×1
asmx ×1
concurrency ×1
debugging ×1
dictionary ×1
endpoint ×1
https ×1
iis ×1
security ×1
soap ×1
using ×1
vb.net ×1
wcf-binding ×1
wcf-client ×1
web-services ×1