在OperationContract中指定操作不会导致在WSDL

时间:2015-08-27 21:22:35

标签: c# wcf tfs wsdl .net-4.5

我有一个奇怪的问题,我一直把头发拉过来。我正在尝试在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

1 个答案:

答案 0 :(得分: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", Name = "Notify", ReplyAction = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/ResponstToNotify")]
        [XmlSerializerFormat(Style = OperationFormatStyle.Document)]
        void Notify(string eventXml, string tfsIdentityXml, SubscriptionInfo SubscriptionInfo);
    }

    [ServiceBehavior(Namespace = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03")]
    public class Service1 : ITfsNotificationService
    {
        public void Notify(string eventXml, string tfsIdentityXml, SubscriptionInfo SubscriptionInfo)
        {
            throw new NotImplementedException();
        }
    }

希望它有所帮助。

My test

Wsdl