标签: wcf

在自定义 UserNamePasswordValidator 中获取 WCF 服务调用的详细信息

我有一个带有我自己的 UserNamePasswordValidator 的 WCF 服务设置。当验证(字符串用户名,字符串密码)方法中的身份验证失败时,我想将详细信息写入日志并抛出FaultException。

我想存储正在调用的特定服务方法的详细信息以及传入的参数以及用户名。

如何从 Validate 方法内部访问这些详细信息?

示例代码如下:

public class ColesUserNameValidator : UserNamePasswordValidator
{

    public override void Validate(string userName, string password)
    {
        if (CheckCredentials(userName, password))
        {
            return;
        }
        else
        {             
            // do something here to get details of the call to the service and send them to a log file 
            throw new FaultException("Unknown Username or Incorrect Password");
        }
    }
Run Code Online (Sandbox Code Playgroud)

wcf

0
推荐指数
1
解决办法
1561
查看次数

WCF和Windows服务中的大文件下载

我一直在创建一个新的服务来下载大文件到客户端.我想在Windows服务中托管该服务.在服务中我写道:

 public class FileTransferService : IFileTransferService
    {
        private string ConfigPath
        {
            get
            {
                return ConfigurationSettings.AppSettings["DownloadPath"];
            }
        }
        private FileStream GetFileStream(string file)
        {

            string filePath = Path.Combine(this.ConfigPath, file);
            FileInfo fileInfo = new FileInfo(filePath);

            if (!fileInfo.Exists)
                throw new FileNotFoundException("File not found", file);

            return new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
        }

        public RemoteFileInfo DownloadFile(DownloadRequest request)
        {
            FileStream stream = this.GetFileStream(request.FileName);

            RemoteFileInfo result = new RemoteFileInfo();
            result.FileName = request.FileName;
            result.Length = stream.Length;
            result.FileByteStream = stream;
            return result;
        }
    }
Run Code Online (Sandbox Code Playgroud)

界面看起来像:

 [ServiceContract]
    public interface IFileTransferService
    {
        [OperationContract] …
Run Code Online (Sandbox Code Playgroud)

.net c# windows wcf web-services

0
推荐指数
1
解决办法
6569
查看次数

iPhone上的WCF双工连接?

是否可以在iPhone中使用WCF双工连接?

最好的祝福,

c# iphone ajax wcf web-services

0
推荐指数
1
解决办法
784
查看次数

调用WCF服务的多种方法

我有一个类用我的WCF服务处理我的应用程序中的所有交互,似乎MSDN说使用With)_语句与WCF是坏的 - 我可以看到为什么这是坏的并同意它(http:/ /msdn.microsoft.com/en-us/library/aa355056.aspx)

我的问题是,他们建议的实现方法将意味着我有10个方法[作为我的服务中的10个公共方法]将具有相同的结构代码,这当然不遵循DRY主体 - 代码看起来类似于以下:

try
{
    results = _client.MethodCall(input parameteres);
    _client.Close();
}
catch (CommunicationException)
{
    if (_client != null && _client.State != CommunicationState.Closed)
    {
        _client.Abort();
    }
}
catch (TimeoutException)
{
    if (_client != null && _client.State != CommunicationState.Closed)
    {
        _client.Abort();
    }
}
catch (Exception ex)
{
    if (_client != null && _client.State != CommunicationState.Closed)
    {
        _client.Abort();
    }
    throw;
}
Run Code Online (Sandbox Code Playgroud)

这还没有任何日志记录,但当然我开始记录它时,我将不得不在几乎10个不同的地方添加日志记录工作

有没有人有任何关于我如何在重用代码方面更有资源的提示

谢谢

保罗

wcf design-patterns principles

0
推荐指数
1
解决办法
422
查看次数

WCF是否适合现实世界?

我在这里阅读http://arunatennakoon.blogspot.com/2010/11/things-i-learn-new-this-week.html

Friday, November 12, 2010
Things I learn new this week
1. Never ever use WCF.
---------------------

here is why
1. IIS 7 doesn't support .svc file format by default. So you need to
Run Code Online (Sandbox Code Playgroud)

安装一些扩展文件.所以新产品的工作量很大.

2. I found it very hard to configure security settings. when i
Run Code Online (Sandbox Code Playgroud)

试图配置它第一次抛出所有类型的错误.

3. After installing WCF in IIS, sometimes it's trowing an exception
Run Code Online (Sandbox Code Playgroud)

指的是temp目录.要解决此问题,您必须重新编译应用程序并重新分发

and a lot more...
Run Code Online (Sandbox Code Playgroud)

那么你会冒风险使用WCF吗?

我想知道每年有数百至数十亿的真实世界的例子.

asp.net wcf

0
推荐指数
2
解决办法
743
查看次数

保护WCF服务

我正在尝试使用ProtectionLevel属性在WCF Web服务上设置安全性:

[ServiceContract(ProtectionLevel= ProtectionLevel.EncryptAndSign)]
Run Code Online (Sandbox Code Playgroud)

这会编译,但当我尝试更新另一个项目(同一解决方案)中的服务引用时,Visual Studio会抛出异常.

System.InvalidOperationException:必须保护请求消息.这是合同操作所必需的('IStorageService','tempuri.org/';).保护必须由绑定提供('WSHttpBinding','tempuri.org/';).

我还需要设置什么来实现这一目标?

wcf web-services

0
推荐指数
1
解决办法
2451
查看次数

ASP.NET Web App 和 C# 应用程序之间的双向通信

我需要构建一个可以双向通信的网站和应用程序。我将使用 ASP.NET 构建网站,并使用 C# 构建应用程序。

我将自己托管该网站,它将与应用程序在同一台计算机上运行。

我不知道在两者之间发送数据的最佳技术是什么。C# 应用程序需要一直运行。我应该构建一个 C# 控制台应用程序,然后隐藏控制台窗口吗?或者其他类型的应用程序更合适?

我一直在浏览 Web,发现了几种不同的建议,包括套接字、消息队列、远程处理和 WCF。一些指示将不胜感激 - 我对这一切都很陌生。

谢谢。

编辑将使用请求-响应模式,Web 应用程序始终是实例化请求的应用程序。这就是我所说的双向通信。

Web应用程序将向后端应用程序发送请求,后端应用程序将执行一些处理,然后将响应发送回Web应用程序。JSON 将用于来回发送数据。

我将使用 SQL Server Express 2008 R2,后端应用程序将是唯一与数据库通信的应用程序。Web 应用程序主要关注表示层。

后端应用程序将具有内存中的对象,这些对象在应用程序启动时实例化(从数据库加载数据),然后持久化到数据库(在执行期间和关闭之前)。C# 控制台应用程序适合这种事情吗?

c# sockets asp.net wcf remoting

0
推荐指数
1
解决办法
8458
查看次数

SAP BAPI 事务未从 WCF 提交

从我的 WCF 服务,我需要在 SAP 系统中创建一个采购订单,它正在创建。但是当我尝试提交事务时,它在 SAP 系统中没有影响。

我从 SAP 获取 PONumber,但它没有提交。

任何人都可以帮助我解决这个问题。

这是我的代码:

NFCLMasters.ZMASTERDATA zmobj = new NFCLMasters.ZMASTERDATA();
            NFCLMasters.ZMASTERDATAResponse zmresponse = new NFCLMasters.ZMASTERDATAResponse();
            NFCLMasters.ZSM_WH_MST[] zmwarehousemaster = new NFCLMasters.ZSM_WH_MST[10];
            NFCLMasters.zws_mst mst = new NFCLMasters.zws_mst();
            zmobj.IWHMST = "X";
            zmobj.WHMST_LINES = zmwarehousemaster;
            zmresponse = mst.ZMASTERDATA(zmobj);

            NFCLTransactions.BAPI_PO_CREATE1 Zpo = new NFCLTransactions.BAPI_PO_CREATE1();
            NFCLTransactions.BAPI_PO_CREATE1Response Zporesponse = new NFCLTransactions.BAPI_PO_CREATE1Response();
            NFCLTransactions.zws_lo SapTrasactions = new NFCLTransactions.zws_lo ();
            // Data objects
            NFCLTransactions.BAPIMEPOHEADER poheader = new NFCLTransactions.BAPIMEPOHEADER();
            NFCLTransactions.BAPIMEPOHEADERX poheaderx = new NFCLTransactions.BAPIMEPOHEADERX();
            NFCLTransactions.BAPIMEPOITEM[] poitem = new NFCLTransactions.BAPIMEPOITEM[1];
            NFCLTransactions.BAPIMEPOITEMX[] poitemx = new …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net wcf saprfc

0
推荐指数
1
解决办法
1453
查看次数

如何处理处于故障状态的 WCF 服务客户端?

异步使用 WCF 服务。如果我不能连接到服务或发生异常就跑到故障状态,并将其错误写入Error的性能AsyncCompletedEventArgs

我与服务客户端有什么关系?我无法关闭它,因为它会抛出一个CommunicationObjectFaultedException. 记录错误后我还需要做什么?

这是我的代码:

MyServiceClient serviceClient = new MyServiceClient();

//Close the connection with the Service or log an error
serviceClient.JustAMethod += (object sender, AsyncCompletedEventArgs args) =>
{
    if (args.Error != null)
    {
        //Log error
        ErrorHandler.Log(args.Error);
    }
    else
    {
        serviceClient.Close();
    }
};

//Call the service
serviceClient.JustAMethodAsync();
Run Code Online (Sandbox Code Playgroud)

c# wcf asynchronous

0
推荐指数
1
解决办法
4169
查看次数

C# 非静态字段、方法或属性“HttpContext.Request”需要对象引用

我正在尝试创建一个通用工厂类来调用 WCF 并注入一些标头。在这个类中,我试图读取 HTTP 标头属性。

    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using ServiceReference;
    using Microsoft.AspNetCore.Http;
namespace Service
{
     public class ServiceFactory
        {

            public static ServiceClient Create()
            {
                ServiceProxy service = new ServiceProxy();
                string userName = HttpContext.Request.Headers["AUTH_USERNAME"];
                string authenricationType = HttpContext.Request.Headers["AUTH_TYPE"];

                using (new System.ServiceModel.OperationContextScope((System.ServiceModel.IClientChannel)service.InnerChannel))
                {          
                    HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                    requestMessage.Headers["AUTH_USERNAME"] = userName;
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;

                    requestMessage.Headers["AUTH_TYPE"] = authenricationType;
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
                }
                return service;
            }       
        }
}
Run Code Online (Sandbox Code Playgroud)

但是我收到一个编译错误,因为“非静态字段、方法或属性 'HttpContext.Request' 需要一个对象引用。由于我不是从静态方法或类调用,这是怎么发生的。任何帮助都会受到高度赞赏。

谢谢你。

c# wcf .net-core

0
推荐指数
1
解决办法
2628
查看次数