Tag: #wcf

如何向WCF服务添加跨域支持

我正在尝试允许来自我在localhost:80托管的javascript应用程序的POST请求到托管在不同端口的WCF REStful服务,但不知何故它不起作用。 我已经尝试在标题中添加自定义属性,并在我的服务的JSONData方法中以编程方式添加它,但我仍然在我的响应中得到’405 Method not allowed’。 这里适当的方法是什么? 这是我的界面: namespace RestService { public class RestServiceImpl : IRestServiceImpl { #region IRestServiceImpl Members public string JSONData() { HttpContext.Current.Response.AddHeader(“Access-Control-Allow-Origin”, “*”); return “Your POST request”; } #endregion } } 和服务代码: using System.ServiceModel; using System.ServiceModel.Web; using System.Web.Script.Services; namespace RestService { [ServiceContract] public interface IRestServiceImpl { [OperationContract] [ScriptMethod] [WebInvoke(Method = “POST”, ResponseFormat […]

如何异步调用wcf服务

如果wcf服务设计如下,那么请指导我如何从客户端Asynchronously调用Add()函数。 谢谢 [ServiceContract] public interface IAddTwoNumbers { // If the asynchronous method pair // appears on the client channel, the client can call // them asynchronously to prevent blocking. [OperationContract (AsyncPattern=true)] IAsyncResult BeginAdd(int a, int b, AsyncCallback cb, AsyncState s); [OperationContract] int EndAdd(IAsyncResult r); // This is a synchronous version of the BeginAdd/EndAdd pair. // […]

如何将标头中的用户名/密码传递给SOAP WCF服务

我正在尝试使用第三方Web服务https://staging.identitymanagement.lexisnexis.com/identity-proofing/services/identityProofingServiceWS/v2?wsdl 我已将其添加为服务引用,但我不确定如何传递标头的凭据。 如何使标头请求与此格式匹配? 12345/userID password123 d+VxCZX1cH/ieMkKEr/ofA== 2012-08-04T20:25:04.038Z

WCF服务属性用于记录方法调用和exception

我需要在WCF服务中记录每个方法调用,并抛出任何exception。 这导致了许多冗余代码,因为每个方法都需要包含类似于此的样板: [OperationContract] public ResultBase Add(int x, int y) { var parameters = new object[] { x, y } MyInfrastructure.LogStart(“Add”, parameters); try { // actual method body goes here } catch (Exception ex) { MyInfrastructure.LogError(“Add”, parameters, ex); return new ResultBase(“Oops, the request failed”, ex); } MyInfrastructure.LogEnd(“Add”, parameters); } 有没有办法可以将所有这些逻辑封装到MyServiceLoggingBehaviorAttribute属性中,我可以将其应用于服务类(或方法),如下所示: [ServiceContract] [MyServiceLoggingBehavior] public class MyService { […]

“不要在Design中使用Abstract Base类; 但在建模/分析中“

虽然我在OOAD有一些经验,但我是SOA的新手。 SOA设计的一个指导原则是“仅使用抽象类进行建模。 从设计中省略它们。 抽象的使用可以有助于建模(分析阶段)。 在分析阶段,我想出了一个BankAccount基类。 从中派生的专业类是“FixedAccount”和“SavingsAccount”。 我需要创建一个服务,返回用户的所有帐户(帐户列表)。 应满足要求的服务结构应该是什么? 注意:如果您可以使用WCF提供代码演示,那将会很棒。

如何将lambda表达式传递给WCF服务?

我目前的项目是使用IDesign架构,所以我的所有层都是服务。 我希望在我的资源访问层的CRUD中使用我的Read方法以lambda表达式的forms获取谓词以及要拉取的相关对象列表。 这样,资源访问层将非常通用。 [OperationContract] Result ReadObjects(Func predicate, string[] includes); 现在我来发现一些应该是显而易见的事情,那就是我无法序列化lambda表达式。 我研究了将字符串解析为lambda表达式,但这也是不行的。 有什么方法可以用来将lambda表达式传递给服务吗? 有没有更好的方法来做我想做的事情?

从WCF服务调用异步方法

我想从WCF服务调用异步方法,如: [ServiceContract] interface IService { [OperationContract] int SomeMethod(int data); } int SomeMethod(int data) { var query = … build LINQ query; var response = await query.ToListAsync(); return response.Length; } 我不想将async添加到IService接口或SomeMethod方法。 使用异步方法是一个内部问题,不应该在接口中反映出来。 我怎样才能做到这一点? 澄清: 我的问题是在非async方法中使用await 。 我不希望服务合同发生变化(客户端不一定知道async是什么),我不想将方法拆分为BeginSomeMethod和EndSomeMethod 。 我想要一个await 内部使用await方法。