相关疑难解决方法(0)

如何为每个WCF调用添加自定义HTTP标头?

我有一个托管在Windows服务中的WCF服务.使用此服务的客户端每次调用服务方法时都必须传递一个标识符(因为该标识符对于被调用的方法应该做什么很重要).我认为以某种方式将此标识符放入WCF头信息是个好主意.

如果是个好主意,我该如何自动将标识符添加到标题信息中.换句话说,每当用户调用WCF方法时,标识符必须自动添加到标头中.

更新: 使用WCF服务的客户端是Windows应用程序和Windows Mobile应用程序(使用Compact Framework).

wcf

157
推荐指数
9
解决办法
16万
查看次数

如何为WCF IErrorhandler设置web.config

无法使用正确的web.config将IErrorHandler集成到我的项目中

我有一个成功运行的WCF,正在被.net 4中的webclients使用,但是当我尝试将IErrorhandler设置为全局错误记录器作为所有我的所有服务方法的捕获时,事情正在快速失败 - 主要与web.config部分有关!请帮忙.

这三项服务是:IReport,IServiceCustomer,IServiceUser

在一个名为MyErrorClass.cs的单独类中实现了IErrorHandler,如下所示:

namespace CustomerWcfService
{
public class WcfErrorHandler : IErrorHandler
{
   /// <summary>
    /// Enables the creation of a custom <see cref="T:System.ServiceModel.FaultException`1"/> that is returned from an exception in the course of a service method.
    /// </summary>
    /// <param name="error">The <see cref="T:System.Exception"/> object thrown in the course of the service operation.</param><param name="version">The SOAP version of the message.</param><param name="fault">The <see cref="T:System.ServiceModel.Channels.Message"/> object that is returned to the client, or service, in the duplex case.</param>
    public void …
Run Code Online (Sandbox Code Playgroud)

wcf web-config ierrorhandler

12
推荐指数
2
解决办法
6310
查看次数

何时何地设置自定义IOperationInvoker?

我正在尝试扩展WCF,以便我可以拥有一个RESTful Web服务,其中,对于每个操作,我执行HTTP Authorization标头的验证,其值用于调用Login()方法.

登录完成后,我希望调用操作的相应方法检查是否抛出了安全异常,在这种情况下,我将使用适当的HTTP状态代码回复自定义的"访问被拒绝"消息.

考虑到这一点,我认为实现一个IEndpointBehavior,它将IOperationInvoker的实现应用于每个操作(设置DispatchOperation.Invoker属性)将是一个好主意.

我决定使用Decorator设计模式实现IOperationInvoker.我的实现需要在其构造函数中使用另一个IOperationInvoker,方法调用将被委托给它.

这是我的IOperationInvokerImplementation:

    public class BookSmarTkOperationInvoker : IOperationInvoker{

    private readonly IOperationInvoker invoker;

    public BookSmarTkOperationInvoker(IOperationInvoker decoratee)
    {
        this.invoker = decoratee;
    }

    public object[] AllocateInputs()
    {
        return this.invoker.AllocateInputs();
    }

    public object Invoke(object instance, object[] inputs, out object[] outputs)
    {
        BeforeOperation(); // Where there's code to perform the login using WebOperationContext.Current
        object o = null;
        try
        {
            o = this.invoker.Invoke(instance, inputs, out outputs);
        }
        catch (Exception exception)
        {
            outputs = null;
            return AfterFailedOperation(exception); // Return a custom access denied …
Run Code Online (Sandbox Code Playgroud)

wcf

10
推荐指数
2
解决办法
6329
查看次数

标签 统计

wcf ×3

ierrorhandler ×1

web-config ×1