【发布时间】:2015-08-27 21:22:35
【问题描述】:
我有一个奇怪的问题,我一直在拔头发。我正在尝试在 WCF 中创建 TFS 事件处理程序服务,部分要求是生成具有特定命名空间和操作的 SOAP 1.2 信封。
基本界面如下所示:
[ServiceContract(Namespace="http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03")]
public interface ITfsNotificationService
{
[OperationContract(Action="http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify", ReplyAction="*")]
[XmlSerializerFormat(Style = OperationFormatStyle.Document)]
void Notify(string eventXml, string tfsIdentityXml, SubscriptionInfo SubscriptionInfo);
}
但是,当我尝试使用 WcfTestClient 访问此服务时出现错误,并且界面中没有显示任何方法:
The contract 'ITfsNotificationService' in client configuration does not
match the name in service contract, or there is no valid method in this
contract.
但是,如果我从操作合同中删除 action 属性,它运行良好(但会有错误的 Action 方法,其中包括接口名称)并且没有任何错误。显然错误是指消息的后半部分(或者此合约中没有有效的方法)
当我查看生成的 WSDL 时,使用 action 属性时没有生成任何操作元素,但是当我只指定一个空的[OperationContract] 时。
关于我在这里做错了什么的任何线索?
仅供参考,这是基于此处的示例:http://www.ewaldhofman.nl/post/2010/08/02/how-to-use-wcf-to-subscribe-to-the-tfs-2010-event-service-rolling-up-hours.aspx
【问题讨论】:
-
您是否尝试在回复中指定类似的命名空间?像这样:回复=“schemas.microsoft.com/TeamFoundation/2005/06/Services/…”
-
@RicardoPontual - 我是否包含 ReplyAction 都没有关系。同样的问题。
-
我通常会在不采取行动/回复的情况下遵守运营合同。它们用于自定义您的消息,但在您的示例中它们不会有太大变化,因为操作的默认名称(如果缺少)是:[服务合同的命名空间]/[服务合同名称]/[操作名称],即:schemas.microsoft.com/TeamFoundation/2005/06/Services/…,因此您可以在没有操作属性的情况下离开您的操作合同。
-
@RicardoPontual - 否。该操作中不能包含服务合同名称,否则 TFS 将无法识别它,这就是为什么您必须指定不包含合同名称的名称。
-
明白。尝试指定动作名称并删除replyAction,如下所示:[OperationContract(Action="schemas.microsoft.com/TeamFoundation/2005/06/Services/…", Name = "Notify")]