问题标签 [wcf-extensions]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
342 浏览

c# - WCF Client Extensibility: IParemeterInspector.AfterCall and exception handling

For my WCF client, I'd like to be able to do some pre and post work for every operation of a given endpoint.

  • The pre work would like to make use of the operation name and the input arguments.
  • The post work would like to make use of (again) the operation name and the original input arguments as well as the outputs/return value or any exception that occurred.

Given this, the IParameterInspector (with its BeforeCall and AfterCall) gives me almost everything I need. The problem is that

  • in the case of an exception, AfterCall is not called (see here).

To help with that problem, I can add an IClientMessageInspector since its AfterReceiveReply does get called in the face of an exception. This gives me the ability to

  • determine if an exception (fault) occurred or not.
  • do post work in the face of an exception

Question:

  • Is there a way with the IClientMessageInspector.AfterReceiveReply to get (or create the equivalent) exception that represents what will eventually be thrown to the callers. And if so, is there a way to mark the exception as handled such that the callers will not get the exception?
  • Or, is there some other extensibility mechanism or other approach I should be using to meet my goals?
0 投票
0 回答
74 浏览

c# - 扩展 WCF 紧凑/自定义标头

我正在开发一个应用程序,它将部署在包括 Windows Phone 在内的各种平台上。因此,我只能访问 WCF Compact / Portable 类。

我需要能够捕获每个传出请求和传入响应,以便将标头应用到请求中,并从响应中读取标头。

在扩展标准 WCF 时,我可以使用自定义行为来实现这一点,但是在 WCF compact 中不支持此功能,因此,我可以使用以下代码将标头附加到特定请求:

但是,我无法在此示例中捕获响应标头。我也担心这不是线程安全的(可能同时发生多个请求)。最后,我想以一种对开发人员透明的方式来实现这个功能——这样他们就不需要做任何特殊的请求。我认为我应该能够使用类似于 IClientMessageFormatter 的东西来实现它,但是我不知道如何在 WCF 紧凑型中实现它。

任何帮助将不胜感激。

谢谢大卫

0 投票
0 回答
52 浏览

wcf - HttpContext.Current is null in WCF custom messageencoder

I've been added aspNetCompatibilityEnabled="true" attribute to serviceHostingEnvironment config in my WCF service project, AspNetCompatibilityRequirementsMode.Required to service, but still get null HttpContext.Current value in ReadMessage. How to fix this problem? I use custom binding with http transport + custom host factory.

0 投票
1 回答
137 浏览

c# - 将对象注入 WCF 管道,在每次 OperationContract 调用之前和之后进行工作

我正在寻找一种方法来跟踪花费在数据库上的总时间,并将其合并到一个服务操作调用甚至整个会话中。由于我目前使用的是 default PerCall InstanceContextMode,因此每次调用服务方法时都会调用 Service 类的构造函数,所以我想像挂钩在每个服务方法之前和之后调用的一些管道方法,调用一个非空的构造函数。然后注入一个对象以进一步传递到层次结构中:

然后我将在服务合同范围之外引用它,并能够在那里记录它。

就像现在一样,对我来说实现这种行为的“最简单”的方法是在每个服务方法的最后调用一个日志记录函数,但如果有更好的方法,我觉得它不是很漂亮。

在 IIS 上托管 WCF Web 服务时,我尝试遵循Explicitly call a service constructorHooking into wcf pipeline和一些Carlos Figueira MSDN 博客:WCF Extensibility,但没有取得多大成功。我也很难找到很多关于它的文档。换句话说,我被卡住了。

0 投票
1 回答
135 浏览

c# - 如何:c# XML InfoSet 到 JSON

因此,WCF 采用 JSON,并且无论出于何种原因将其转换为 XML 信息集(请参阅:https ://stackoverflow.com/a/5684703/497745 )。然后,它使用 JsonReaderDelegator 在内部读回此 XML 信息集(请参阅:https ://referencesource.microsoft.com/#System.Runtime.Serialization/System/Runtime/Serialization/Json/JsonReaderDelegator.cs,c0d6a87689227f04 )。

我正在对 WCF 执行流程进行一些非常深入的修改,我需要将 XML Infoset 反转回原始 JSON。

.NET 或外部是否有可以获取 WCF 生成的 XML 信息集并将其转换回其原始 JSON 的库?

0 投票
0 回答
440 浏览

c# - Unity DI 与 WCF 客户端

我正在为我们的项目使用 UnityContainer。我需要为所有外出的 wcf 调用添加自定义标头,因此我实现了 IClientMessageInspector 和 IEndpointBehavior。现在我正在尝试使用 UnityContainer Property Injection 从某个对象中获取标头值。相同的属性注入在 IClientMessageInspector 外部工作,但不在我的自定义 Clientmessageinspector 内部工作。

属性注入

_container 总是以 null 的形式出现。

我们可以像使用其他类一样在 MessageInspector 中使用 UnityContainer 吗?

0 投票
0 回答
98 浏览

c# - WCF 根据需要标记所有值类型数据成员

我在 WCF 服务的上下文中。我正在尝试验证我的客户是否向我发送了一份有效的合同。

在我的公司,我们有数百个数据合同。对我们来说,所有值类型,除了 之外Nullable<T>,都应该根据定义要求存在于请求消息中(否则我们希望将它们显式包装在 中Nullable<T>)。

我知道我可以根据需要标记我的数据成员:

但是对于值类型,我想找到一种方法来为服务而不是每个数据成员全局定义它。为了实现这一目标,正确的 WCF 扩展点是什么?

附加信息:

我遇到了IDispatchMessageInspectorand IDispatchMessageFormatter,但那些只会让我处理整个消息。是否有更好的扩展点,其中属性已经按名称映射到目标数据成员,但尚未实例化为 .NET 类型?或者更好的是,我可以在哪里访问单个数据成员的序列化元数据?

作为我希望找到的参考,当我将类似的解决方案应用于我们JsonSerializer基于ContractResolver. 所以我派生DefaultContractResolver并覆盖:

0 投票
0 回答
2224 浏览

c# - MTOM 消息的类型必须为“application/xop+xml”

我正在使用 C# 调用 Java Webservice。Fiddler 给我的状态是 200。所以我对服务的调用很好。但是 .NET 中的某些内容不喜欢我的 MTOM 消息。有任何想法吗?这是所有细节。

我收到此错误:

堆栈跟踪说:

提琴手的文本回复是这样说的:

提琴手的原始回应是这样说的:

App.config 文件:

0 投票
1 回答
1288 浏览

wcf - IIS 500 错误 WCF 服务和失败的请求跟踪不是信息

我在集成了 AppPool 的 Windows Server 2012 R2 上的 IIS 8.5 中运行了 WCF 服务。

我在服务器中打开 url:http://localhost:50123/MyService.svc

我有HTTP 500 内部服务器错误。(IExplorer 无法显示页面)

我在事件日志、IIS 日志中没有发现问题。

我应用此步骤:https ://peter.hahndorf.eu/blog/iislogging.html

我使用 WCF 跟踪,但没有查看错误消息。

我为所有内容、详细错误日志记录、400-600 范围内的 HTTP 错误设置了“失败的请求跟踪”。

我从%systemdrive%\inetpub\logs\FailedReqLogFiles\W3SVC1打开 fr000001.xml 文件

我只查看 MODULE_SET_RESPONSE_ERROR_STATUS 警告:

ModuleName ManagedPipelineHandler
Notification 128 HttpStatus
500
HttpReason Internal Server Error
HttpSubStatus 0 ErrorCode 0
ConfigExceptionInfo
Notification EXECUTE_REQUEST_HANDLER
ErrorCode 操作成功完成。(0x0)

错误 500:

HttpStatus 500
HttpReason 内部服务器错误

并成功?

ErrorCode 操作成功完成。(0x0)

没有关于错误的更多信息。

关于错误:

我有 IDispatchMessageInspector 和 WCF Inspector

喜欢https://patrickdesjardins.com/blog/wcf-inspector-for-logging

错误与属性有关logFileName="c:\log.txt"

如果路径存在,则一切正常。如果路径不存在,我会收到 Http 500 错误。

这意味着代码中有一个未经处理的异常。

事件查看器、IIS 日志、WCF 跟踪、失败的请求跟踪未显示错误消息,为什么?如何获得完整的错误信息?操作系统无论如何都没有记录错误?

0 投票
0 回答
53 浏览

c# - Wcf 操作调用程序,记录 InvokeEnd 中的输入参数

我遇到了 WCF 项目的问题。我正在尝试扩展实现自定义操作调用程序的 wcf 行为以记录所有异常,保存操作名称和操作输入。同步函数没有问题,但是异步函数我不知道如何在 InvokeEnd 中获取输入参数,这是我写的代码:

如果 _baseInvoker.InvokeBegin 抛出异常,我需要记录 InvokeBegin 函数的“输入”参数。我想我应该使用 _baseInvoker.InvokeBegin 的“状态”参数,但我现在不知道如何传递我的自定义参数而不是“状态”,函数永远不会结束。使用调试器检查代码,“state”参数似乎是一个 System.ServiceModel.Dispatcher.MessageRpc.Wrapper 对象。

有什么建议么?谢谢