Tag: #wcf

WCF NetTcpBinding是否提供持久连接?

使用WCF制作客户端/服务器风格的应用程序,但我找不到任何解释NetTcpBinding是否提供持久连接的文档? 我希望我的客户端连接并保持连接到服务器数周。 (是的,我知道我需要处理断线等…) NetTcpBinding是否允许这样的长连接? 如果有,我需要指定什么或这是默认行为?

WCF应用程序 – 需要http和tcp绑定的“app start”代码

我有一个WCF应用程序,需要一些应用程序初始化代码在应用程序启动时触发。 目前代码位于global.asax.cs中的Application_Start方法中: protected void Application_Start(object sender, EventArgs e) { // Whatever.. } 但是,我的WCF应用程序同时具有http(asp.net)和TCP(netTcpBinding)端点,具体取决于所调用的服务。 此代码仅针对普通的http端点而不是TCP触发。 无论是通过tcp还是http进行客户端调用,我都需要启动应用程序启动代码。 最好的方法是什么? 谢谢

使用Protobuf-net和Monotouch for IOS序列化IEnumerable槽WCF

我正在尝试在Monotouch / Monodevelop上为IOS编写WCF服务。 我使用[DataMember] / [DataContract]等标准属性作为我的可序列化对象,使用[ServiceContract] / [OperationContract]作为我的界面。 一切正常,但是当我尝试在接口实现(服务器端)上实现返回IEnumerable的方法时,它没有用。 所以为了解决我的问题,我尝试使用最新版本的protobuf-net protobuf-net v2 beta r404。 但是我仍然从Protobuf-net那里得到序列化错误。 请注意,“MyObject”中的IEnumerable序列化没有问题。 以下是我的代码现在的样子: 为MyObject: [ProtoContract] public class MyObject { public MyObject () { } [ProtoMember(1)] public int Id {get;set;} [ProtoMember(2)] public IEnumerable myObjects {get;set;} } 我的界面(Windows上的服务器端): [ServiceContract] public interface ITouchService { [OperationContract, ProtoBehavior] MyObject Execute(); [OperationContract, ProtoBehavior] IEnumerable ExecuteENUM (); } […]

如何向/与RESTful WCF服务传递和使用JSON参数?

我是RESTful服务的初学者。 我需要创建一个接口,客户端需要传递最多9个参数。 我宁愿将参数作为JSON对象传递。 例如,如果我的JSON是: ‘{ “age”:100, “name”:”foo”, “messages”:[“msg 1″,”msg 2″,”msg 3”], “favoriteColor” : “blue”, “petName” : “Godzilla”, “IQ” : “QuiteLow” }’ 如果我需要在下面执行下面的服务器端方法: public Person FindPerson(Peron lookUpPerson) { Person found = null; // Implementation that finds the Person and sets ‘found’ return found; } 问题(S): 我应该如何使用上面的JSON字符串从客户端进行调用? 我如何创建RESTful服务方法的签名和实现 接受这个JSON, 将它解析并反序列化为Person对象和 调用/将FindPerson方法的返回值返回给客户端?

WCF – 使用相同数据协定的多个服务合同

我有一个关于WCF大师的新问题。 所以,我有一个类User ,它接近我用于数据库操作的DB的’User’表示。 现在,我想有两个不同的服务合同,使用这个类作为数据合同,但每个都以他们自己的方式……我的意思是, public class DBLayer { void InsertUsers(List userList) { // both ‘PropertyVisibleForService1’ and ‘PropertyVisibleForService2’ // are used HERE to be inserted into their columns } } [DataContract] public class User { [DataMember] public string PropertyVisibleOnlyForService1{…} [DataMember] public string PropertyVisibleOnlyForService2{…} } [ServiceContract] public interface IService1 { List GetUsers(); // user with ‘PropertyVisibleOnlyForService1’ inside […]

通过wcf服务发送带有自定义属性的对象

我刚开始学习WCF,因为我需要它来完成学校作业。 但是当我尝试发送带有一些自定义属性的对象时,我遇到了问题。 对象是: [DataContract] public class Person { [DataMember] [Searchable(“ID”)] public virtual String ID { get; set; } [DataMember] [Searchable(“LastName”)] public virtual String LastName { get; set; } [DataMember] [Searchable(“FirstName”)] public virtual String FirstName { get; set; } } 自定义属性是: [DataContract] [AttributeUsage(AttributeTargets.Property)] public class Searchable:Attribute { public Searchable(String PropertyName) { this.PropertyName = PropertyName; } [DataMember] […]

获取403 Forbidden错误。 客户端身份validation方案“Anonymous”禁止HTTP请求

我所遇到的这个问题并没有发生在所有访问我们服务的客户端上,但是一致的是,当错误确实发生时,它发生在少数客户端的同一服务调用上。 以下是例外的详细信息: System.ServiceModel.Security.MessageSecurityException使用客户端身份validation方案“Anonymous”禁止HTTP请求。 System.ServiceModel.Security.MessageSecurityException:使用客户端身份validation方案“Anonymous”禁止HTTP请求。 > —> System.Net.WebException:远程服务器返回错误:(403)Forbidden。 System.Service.Net.HttpWebRequest.GetResponse () at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)—内部exception堆栈跟踪结束—服务器堆栈跟踪:在System.ServiceModel.Security .IssuanceTokenProviderBase 1.DoNegotiation(TimeSpan timeout) at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.TlsnegoTokenProvider.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan timeout) at System.ServiceModel.Security.SecurityUtils.OpenTokenProviderIfRequired(SecurityTokenProvider tokenProvider, TimeSpan timeout) at System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.SecurityChannelFactory 1.DoNegotiation(TimeSpan timeout) at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.TlsnegoTokenProvider.OnOpen(TimeSpan timeout) at […]

将多个参数POST到WCF服务

我想了解WCF,所以我的问题可能很愚蠢。 我相信我对“GET”操作有着坚定的理解。 我现在正在进行一些“POST”操作。 我的问题是,我可以使用WebInvoke编写一个接受多个参数的WCF服务操作吗? 或者,当我发布数据时,它是否只接受一个序列化参数? 谢谢!

无法在ServiceModel客户端配置部分中找到引用合同“IAuthenticationService”的默认端点元素

我尝试创建一个简单的WCF应用程序,我没有更改任何现有的默认配置。 我尝试使用使用svcutil.exe生成的TestClient来使用该服务。 它”Could not find default endpoint element that references contract ‘IAuthenticationService’ in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.”显示错误消息”Could not find default endpoint element that references contract ‘IAuthenticationService’ in […]

在进行异步WCF调用时,首选哪种方式?

当异步调用WCF服务时,似乎有两种方法可以完成。 1。 WcfClient _client = new WcfClient(); public void One() { _client.BegindoSearch(“input”, ResultOne, null); } private void ResultOne(IAsyncResult ar) { string data = _client.EnddoSearch(ar); } 2。 public void Two() { WcfClient client = new WcfClient(); client.doSearchCompleted += TwoCompleted; client.doSearchAsync(“input”); } void TwoCompleted(object sender, doSearchCompletedEventArgs e) { string data = e.Result; } 使用新的Task类,我们可以通过在同步中包装同步操作来轻松实现第三种方法。 3。 public void […]