Tag: #wcf

在同一个具有相同名称的合同中不能有两个操作(Async和Non)

当激活以下服务时,我得到以下exception(在相同的合同中不能有两个操作,具有相同的名称,方法ExecuteAsync和Execute)。 [ServiceContract] public interface IMyService { [OperationContract] byte[] Execute(MyRequest request); [OperationContract] Task ExecuteAsync(MyRequest request); } 我想如果您使用svcutil.exe来创建服务引用,这是有道理的,因为基于任务的操作是自动为您创建的。 但是,我不想添加服务引用,而只是使用标准的ChannelFactory来创建WCF通道。 如果不将异步方法重命名为其他方法,还有其他方法吗? 或者我必须在Task.Run中的客户端上包装sync方法吗?

WCF – 如何有效地发送GUID(而不是字符串)

我有一个包含大量数据传输对象的集合,我需要通过WCF将其发送到Silverlight客户端。 我正在使用默认的DataContractSerializer和HTTPS通道。 以下是一种DTO的示例。 [DataContract(Namespace = Constants.OrgStructureNamespace)] public class EntityInfo : IExtensibleDataObject { [DataMember] public Guid EntityID { get; set; } [DataMember] public EntityType EntityType { get; set; } [DataMember] public IList EntityVersions { get; set; } [DataMember] public IList OrganisationStructures { get; set; } #region IExtensibleDataObject Members … #endregion } 服务器端的域实体使用GUID作为主键。 这些序列化为36字节长的字符串。 二进制forms的GUID应该只有16个字节长。 是否有一个技巧可以让DataContractSerializer将我的GUID序列化为二进制而不是作为冗长的字符串来提高性能?

使用HttpRequestMessage或Stream上传REST文件?

上传REST客户端文件的更好方法是什么? 从WCF Web API文档 [WebInvoke(UriTemplate = “thumbnail”, Method = “POST”)] public HttpResponseMessage UploadFile(HttpRequestMessage request) { 来自多个论坛post: 带有其他参数的WCF REST文件上载 [WebGet(UriTemplate=””, Method =”POST”] public string UploadFile(Stream fileContents) 我理解,第一种方法允许直接从普通的HTML表单发布文件。 在我发现的所有论坛post中,第二种方法似乎更常见。 你会推荐什么?为什么? 可以从各种语言和平台访问REST API。 对于HttpRequestMessage方法,如何使用WCF HttpClient上传文件? 使用FormUrlEncodedMediaTypeFormatter)

客户端身份validation方案“匿名”禁止HTTP请求。 远程服务器返回错误:(403)禁止

我正在尝试创建一个安全的Web服务。 这是合同和服务实施 [ServiceContract()] public interface ICalculatorService { [OperationContract()] int Add(int x, int y); } [ServiceBehavior(IncludeExceptionDetailInFaults=true)] public class CalculatorService : ICalculatorService { public int Add(int x, int y) { return x + y; } } 这里我有服务代码 var b = new WSHttpBinding(SecurityMode.Transport); b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; b.Security.Message.ClientCredentialType = MessageCredentialType.None; Type contractType = typeof(ICalculatorService); Type implementedContract = typeof(CalculatorService); Uri […]

.NET 4.5和.NET 4.5.1默认启用TLS 1.1和TLS 1.2

在我们的Windows 2012 Server R2上,我们需要禁用TLS 1.0。 但是我们运行.NET 4.5 Wcf服务。 我们发现,如果我们禁用TLS 1.0,WCF服务不再运行,因为我们收到错误’现有连接被远程主机强行关闭’。 .NET 4.5和.NET 4.5.1中是否默认启用了TLS 1.1 / 1.2? 如果没有,我们假设是这样,在我们的WCF项目中,我们强制项目使用TLS 1.1 / 1.2?

将WCF服务转换为RESTful应用程序?

嘿,我没有把wcf变成一个宁静的服务。 所以我想知道是否有人可以在这里启动WCF服务应用程序时采用基本代码: using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; namespace WcfService1 { // 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 IService1 { [OperationContract] string GetData(int value); [OperationContract] CompositeType […]

SOA问题:公开实体

我想在我的3层结构中加入SOA模式。 我在BLL和UI之间创建了一个服务层(WCF主机)。 我的结构设置现在看起来像这样 UI WCF BLL DAL 问题是,我将我的实体放在单独的DLL中(并且它在除了UI之外的所有层中都可见)现在,我需要公开它以便我的服务的使用者可以使用它。在这种情况下,UI。 我怎么可能这样做? Entities.DLL namespace Entities { public class Account { public string AcctID { get; set; } public string AcctName { get; set; } } } 现在,我打算在WCF中使用它 服务接口层 public class AccountService : IAccountService { public Account GetAccount(string AcctID) { //fetch from DAL through BLL } } 只是属性我的实体可以吗? (注意,我也在使用DAL和BLL中的实体) […]

如何调试WCF程序

我的代码使用了大量的WCF调用,当我尝试调试它时,它不会转到服务代码本身。 有没有办法以某种方式调试WCF代码?

C#WCF:在共享库中有一个app.config,提供对服务的访问

我目前有一个包含几个项目的解决方案,其中一个是WCF服务。 我创建了另一个使用静态类的投影,它基本上为WCF客户端的实例提供了一个网关,如下所示: public static class WSGateway { public static DBInteractionGatewayClient MR_WebService { get { return new DBInteractionGatewayClient(); } } } 这是(或者我认为)我可以使用仅在该库中的单个app.config文件,然后其他项目可以只引用它并从该属性获取对该客户端的引用。 但问题是,当一个项目试图访问该属性时,会抛出一个exception,告诉我在应用程序中需要app.config ,当我将app.config复制到我的网关库时,它可以工作。 有没有办法避免在应用程序中有多个app.config文件,并且只有一个可能是一个库? [更新]解决方案: 按照Anderson Imes的建议,现在我决定对类中的客户端引用配置进行硬编码,从而消除了对多个app.config的需求。 因此,我从这个( app.config )翻译了我的配置: 对此( static class ): public static class WSGateway { private static WSHttpBinding binding; private static EndpointAddress endpointAddress; static WSGateway() { var readerQuotas = new XmlDictionaryReaderQuotas() […]

WCF服务主机找不到任何服务元数据

我刚学习wcf,目前已经走到了这一步。 CS档案: using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace wcfLib { [ServiceContract] public interface IfaceService { [OperationContract] int wordLen(string word); } public class StockService : IfaceService { public int wordLen(string word) { return word.Length; } } } 然而,当我试图运行它时,它会弹出一个错误: WCF服务主机找不到任何服务元数据…… 知道它可能是什么? 配置文件: