Tag: #wcf

Serializable和DataContract(不是?)

我在新项目中阅读了一些代码,发现前开发人员正在使用Serializable和DataContract。 [Serializable] 和 [DataContract(Namespace=”Some.Name.Space”, IsReference = true)] 我假设当存在DataContract属性时,WCF将忽略Serializable。 这是正确的假设吗? 如果没有,同时使用两者有什么好处?

WebService添加布尔参数时消耗的WCF?

我在VS2008中创建了默认的WCF服务。 它被称为“Service1” public class Service1 : IService1 { public string GetData( int value ) { return string.Format(“You entered: {0}”, value); } public CompositeType GetDataUsingDataContract( CompositeType composite ) { if ( composite.BoolValue ) { composite.StringValue += “Suffix”; } return composite; } } 它工作正常,接口是IService1: [ServiceContract] public interface IService1 { [OperationContract] string GetData( int value ); [OperationContract] CompositeType […]

System.StackOverflowException,当使用get set属性时?

wcfserviceLibrary.DLL中发生未处理的“System.StackOverflowException”类型exception 代码如下所示。 [DataContract] public class memberdesignations { [DataMember] public string DesigId { get { return DesigId; } set { DesigId = value;} } [DataMember] public string DesignationName { get { return DesignationName; } set { DesignationName = value; } } } 那么我有类型成员名称的方法如下 public List memberdesignations() { List designations = new List(); memberdesignations objmemDesignations; ds = […]

WCF DataContract与DataContract接口

WCF新手。 DataContact类可以从Interfaceinheritance吗? 例如: [DataContract(Namespace = ………..)] public class VesselSequence : IVesselSequence { [DataMember] public int AllocationId { get; set; } [DataMember] public string ScenarioName { get; set; } } interface VesselSequence : IVesselSequence { public int AllocationId { get; set; } public string ScenarioName { get; set; } }

重复位代码的设计模式/ C#技巧

我有一个WCF服务,它记录任何exception,然后将它们作为FaultExceptions抛出。 我正在做很多重复,例如在每种服务方法中。 try { // do some work } catch(Exception ex) { Logger.log(ex); // actually will be Fault Exception but you get the idea. throw ex; } 我正在寻找一种更优雅的方式,因为我在每个服务中剪切并粘贴try / catch。 是否有一个设计模式/ C#技巧可以用来使这更优雅?

WCF如何启用元数据?

我试图让我的svc文件在IIS下工作。 在我的项目中,当我按F5时,我得到了svc工作。 所以我知道一切都好,对吧? 除了IIS。 我正在使用Windows XP Pro计算机,在IIS中我添加了一个虚拟目录。 这是我的代码:IcarePlanActions(项目:A) namespace WcfServiceLibrary { [ServiceContract] public interface ICarePlanActions { [OperationContract] List GetAllClients(); } } 客户:(项目:A) namespace WcfServiceLibrary { public class Client : ICarePlanActions { public List GetAllClients() { List clients = new List(); clients.Add(“Hendrik de Jong”); clients.Add(“Miep de Berg”); clients.Add(“Jaap Jongeneel”); clients.Add(“Joop Prakman”); clients.Add(“Pieter Schaakman”); return clients; } […]

如何使用autofac注册两个WCF服务合同

我有一个WCF服务,实现了两个服务合同…… public class MyService : IService1, IService2 我自我托管服务…… host = new ServiceHost(typeof(MyService)); 当服务只实现一个服务合同时,一切都工作正常,但是当我尝试设置autofac来注册这两个时: host.AddDependencyInjectionBehavior(_container); host.AddDependencyInjectionBehavior(_container); …它在第二个引发exception,报告: 该值无法添加到集合中,因为该集合已包含相同类型的项:’Autofac.Integration.Wcf.AutofacDependencyInjectionServiceBehavior’。 此集合仅支持每种类型的一个实例。 乍一看,我认为这是说我的两个合同在某种程度上被视为相同的类型,但在二读时我相信它是说AutofacDependencyInjectionServiceBehavior是有问题的类型,即我不能使用它两次! 然而,我发现这篇文章明确显示多次使用它的forms略有不同: foreach (var endpoint in host.Description.Endpoints) { var contract = endpoint.Contract; Type t = contract.ContractType; host.AddDependencyInjectionBehavior(t, container); } 不幸的是,这给出了同样的错误信息。 是否可以在一项服务上注册多个服务合同,如果是,如何?

您可以在WCF服务方法中使用可选参数吗?

我看过这样的post和这个但是它们都是几年前的。 我可以这样做吗? [OperationContract] [FaultContract(typeof(MyCustomFault))] List SelectMany(string partialPartNumber, string division = null);

netTCP绑定Soap安全协商失败

我正在写一个WCF服务需要模拟和会话。 我尝试在我的本地计算机上调用它时没关系,但是在远程计算机上它总是因为这样的错误而失败: 安全支持提供程序接口(SSPI)身份validation失败。 服务器可能未在具有标识“host / hostname”的帐户中运行。 如果服务器在服务帐户(例如,网络服务)中运行,请将该帐户的ServicePrincipalName指定为服务器的EndpointAddress中的标识。 如果服务器在用户帐户中运行,请将该帐户的UserPrincipalName指定为服务器的EndpointAddress中的标识。 如果我提供了upn,它会抛出一个身份失败的exception。 这是我的配置: 服务器配置(APP): 客户端配置: 任何帮助将不胜感激。

DataContract,默认DataMember值

有没有办法在反序列化期间选择不在xml文件中的属性的默认值? 如果xml文件中没有mAge属性,我想使用默认值18.是否可以? [DataContract] public class Person { public Person () { } [DataMember(Name = “Name”)] public string mName { get; set; } [DataMember(Name = “Age”)] public int mAge { get; set; } [DataMember(Name = “Single”)] public bool mIsSingle { get; set; } }; 编辑以回答。 [DataContract] public class Person { public Person () { } [DataMember(Name […]