Tag: #wcf

使用NetTCPBinding回调

NetTCPBinding是否支持回调? 如果是这样,请将我重定向到任何适当的示例。 谢谢

能够在WCF中将主要对象从客户端传送到服务端

在WCF中,在客户端,用户将被认证,他的角色/权限将存储在客户端的Principal / Identity对象中。 经过身份validation后,用户应该只能在某个角色中调用服务方法。 为此,我需要将客户端Principal / Identity对象传输到服务端。 但是一旦我到达服务端,主要对象是Windows Principal,Identity是Windows Identity。 这不允许我检查是否应该根据客户端凭据调用服务方法。 是否可以将我的主体和身份对象从客户端传输到服务器端? 我想将我的主要对象(Generic Principal)传输到服务器端。 可能吗? 请帮忙。 之前我发过类似的问题如下: 将客户端定制的Principal对象转移到WCF服务端 我试图通过答案,但我无法inheritance我的主要对象。 这是细节。 在客户端,我的Principal对象和标识对象在调试期间在立即窗口中如下所示: System.Threading.Thread.CurrentPrincipal {System.Security.Principal.GenericPrincipal} [System.Security.Principal.GenericPrincipal]:{System.Security.Principal.GenericPrincipal} Identity:{System.Security.Principal.GenericIdentity} System.Threading。 Thread.CurrentPrincipal.Identity {System.Security.Principal.GenericIdentity} [System.Security.Principal.GenericIdentity]:{System.Security.Principal.GenericIdentity} AuthenticationType:“”IsAuthenticated:false名称:“” 在服务器端,我的主要对象和标识如下所示: System.Threading.Thread.CurrentPrincipal {System.Security.Principal.WindowsPrincipal} [System.Security.Principal.WindowsPrincipal]:{System.Security.Principal.WindowsPrincipal} Identity:{System.Security.Principal.WindowsIdentity} {System.Security .Principal.WindowsIdentity} [System.Security.Principal.WindowsIdentity]:{System.Security.Principal.WindowsIdentity} AuthenticationType:“NTLM”IsAuthenticated:true Name:“MyDomain \ MyLoginID” 我的WCF客户端如下所示 客户代码: namespace ConsoleApplication1 { class Program { static void Main(string[] args) { […]

如何在没有程序集版本号的情况下指定wcf behaviorExtension类类型?

我有一个使用WCF服务的Web应用程序,该服务使用了behaviorExtension,如下所示: 问题是这个Web应用程序的版本随着每次编译而改变(我认为)并因此使该条目无效。 如何在每次编译时都避免更改版本号? 我可以在代码中指定扩展名吗?

是否可以使用WCF发现来公开使用命名管道的WCF端点?

我有一个使用发现的应用程序,可以在本地部署在同一台PC上或远离它所使用的服务。 有没有办法通过WCF发现公开命名管道绑定? 如果不是,我想我可以在发现服务后进行协商,以确定最合适的绑定。

WCF奇怪的行为

我在使用Web服务时得到了这个: 合同’IServices’的操作’Login’指定要序列化的多个请求体参数,而不包含任何包装元素。 最多可以在没有包装元素的情况下序列化一个body参数。 删除额外的body参数或将WebGetAttribute / WebInvokeAttribute上的BodyStyle属性设置为Wrapped。 我使用界面看起来像: namespace DreamServices { // NOTE: You can use the “Rename” command on the “Refactor” menu to change the interface name “IService1” in both code and config file together. [ServiceContract] public interface IServices { [OperationContract] [WebInvoke(Method = “GET”, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = “LogIn/{username}/{password}”)] string Login(string […]

Silverlight – > WCF – >数据库 – >问题

我有一些调用WCF服务的silverlight代码,然后使用entity framework访问数据库并返回记录。 一切运行正常,但……当我用经典的ADO.NET代码替换entity framework代码时,我收到一个错误: 远程服务器返回错误:NotFound 当我使用unit testing直接调用ADO.NET代码时,它会返回正确的记录,因此它不是ADO.NEt代码的问题。 我使用了fiddler,它似乎说服务找不到“500”错误。 我不认为这与服务有任何关系,因为我唯一改变的是访问数据库的技术。 谁知道我在这里缺少什么?

如何从WCF REST方法返回自定义类型值的Dictionary作为常规JSON对象?

假设我有一个看起来像这样的自定义类型: [DataContract] public class CompositeType { [DataMember] public bool HasPaid { get; set; } [DataMember] public string Owner { get; set; } } 和一个如下所示的WCF REST接口: [ServiceContract] public interface IService1 { [OperationContract] Dictionary GetDict(); } 那么我如何让我的方法实现返回一个看起来像这样的JSON对象… {“fred”:{“HasPaid”:false,”Owner”:”Fred Millhouse”},”joe”:{“HasPaid”:false,”Owner”:”Joe McWirter”},”bob”:{“HasPaid”:true,”Owner”:”Bob Smith”}} 我不希望它看起来像这样: [{“Key”:”fred”,”Value”:{“HasPaid”:false,”Owner”:”Fred Millhouse”}},{“Key”:”joe”,”Value”:{“HasPaid”:false,”Owner”:”Joe McWirter”}},{“Key”:”bob”,”Value”:{“HasPaid”:true,”Owner”:”Bob Smith”}}] 理想情况下,我宁愿不必改变方法的返回类型。 我尝试了很多不同的方法,但找不到有效的解决方案。 令人讨厌的是,使用Newtonsoft.Json在一行中生成正确形状的JSON对象结构很容易: string json = JsonConvert.SerializeObject(dict); 其中dict定义为: Dictionary dict = […]

当前的OperationContext在WCF Windows服务中为null

我正在尝试使用WCF设置发布/订阅系统,并且WCF服务器位于Windows服务中。 绑定是net.TCP。 该服务向客户端提供“订阅”方法,以便客户端可以将回调处理程序注册到将从链接到服务器的DLL引发的事件。 在Subscribe方法中,我尝试使用OperationContext.Current.GetCallbackChannel方法获取回调通道。 当我尝试这个时,OperationContext.Current属性返回NULL。 谁能告诉我在什么情况下这个属性会返回null? 我错过了设置吗? 我将在下面包含服务代码和接口代码。 我在Visual Studio 2012和目标框架4.5中使用c#。 服务: namespace WService { [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] public class WcfPublisherService : IWcfPublisherContract { IOALogic logic = new OAControlExample(); IWcfSubscriberContract _callback = null; public void Subscribe() { _callback = OperationContext.Current.GetCallbackChannel(); logic.BarriersChanged += logic_BarriersChanged; } public void UnSubscribe() { logic.BarriersChanged -= logic_BarriersChanged; } void logic_BarriersChanged(object sender, […]

WCF Web服务,返回错误/exception字符串

我有一组WCF Web服务,如果发生exception,将使用OutgoingWebResponseContext将错误描述返回给调用者。 我的问题是,有时,当出现问题时,Web服务显示为失败 ,带有ERR_CONNECTION_RESET消息,而不是返回错误消息,我想防止这种情况发生。 例如,这是我的漂亮的C#代码,它查询我的Northwind数据库,并返回一个Customer名称列表。 或者更确切地说, 它会这样做 ,但我故意在那里插入一个例外。 public List GetAllCustomerNames() { // Get a list of unique Customer names. // try { throw new Exception(“Oh heck, something went wrong !”); NorthwindDataContext dc = new NorthwindDataContext(); var results = (from cust in dc.Customers select cust.CompanyName).Distinct().OrderBy(s => s).ToList(); return results; } catch (Exception ex) { OutgoingWebResponseContext […]

Net TCP绑定:无法识别URI前缀

这真的让我困扰了几个小时。 我使用TCP绑定创建了最简单的WCF服务。 namespace WcfTcpService { public class TestTcpService : ITestTcpService { public string Hello(string name) { return “Hello, ” + name + “!”; } } } namespace WcfTcpService { [ServiceContract] public interface ITestTcpService { [OperationContract] string Hello(string name); } } Web.config文件包含以下部分: <!– –> <!—-> 此服务托管在IIS中: 现在,当尝试从客户端应用程序添加对net.tcp://localhost:808/WcfTcpService.TestTcpService的引用时,我一直收到错误: The URI prefix is not recognized. Metadata contains a […]