Ask a questionAsk a question
 

AnswerCan not consume TFS Event from WCF Service

  • Saturday, October 31, 2009 2:44 PMAnilCa Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hello,

    I have a WCF service designed to receive an event from the TFS 2008 server, any time any change occurs.  I have tested that I am able to connect to the WCF Serivce end point from the TFS machine, via WcfTestClient.exe (the TFS server and WCF Services are on different machines).

    I have registered for consuming TFS events, with the following command (run on the TFS server):

    BisSubscribe.exe /eventType WorkItemChangedEvent /address http://10.43.200.226:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/mex /server TFS /deliveryType Soap

    (I did NO other modifications on the TFS server).

    I then have the following code:


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    using System.Xml.Schema;
    using System.Xml.Serialization;
    
    namespace WcfServiceForTFS
    {
        // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in App.config.
        [ServiceContract(Namespace = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03")]
        public interface ITFSEventSubscriber
        {
            //[XmlSerializerFormat()]
            [OperationContract(Action = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify")]
            [XmlSerializerFormat(Style = OperationFormatStyle.Document)]
            void Notify(String eventXml, String tfsIdentityXml, SubscriptionInfo SubscriptionInfo);
    
        }
    
        [Serializable]
        [XmlRoot(ElementName = "SubscriptionInfo", IsNullable= false)]
        [XmlType(TypeName= "SubscriptionInfo")]
        [DataContract(Namespace="http://scheams.microsoft.com/TeamFoundation/2005/06/Services/Notification/03")]
        public class SubscriptionInfo
        {
            public SubscriptionInfo()
            {
            }
    
            private int _ID;
    
            [XmlElement(ElementName = "ID", IsNullable = false, DataType = "int")]
            public int ID
            {
                get { return _ID; }
                set { _ID = value; }
            }
    
            private string _classification;
    
            [XmlElement(ElementName = "Classification", IsNullable = true, DataType = "string")]
            public string Classification
            {
                get { return _classification; }
                set { _classification = value; }
            }
    
            private string _subscriber;
    
            [XmlElement(ElementName = "Subscriber", IsNullable = true, DataType = "string")]
            public string Subscriber
            {
                get { return _subscriber; }
                set { _subscriber = value; }
            }
        }
    }
    
    


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    
    namespace WcfServiceForTFS
    {
        // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in App.config.
        public class TFSEventSubscriber : ITFSEventSubscriber
        {
    
            public void Notify(String eventXml, String tfsIdentityXml, SubscriptionInfo SubscriptionInfo)
            {
                System.IO.File.WriteAllText(@"C:\tmp\tfsxml.xml", "HIT!: " + eventXml);
            }
        }
    }
    
    


    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <!-- When deploying the service library project, the content of the config file must be added to the host's 
      app.config file. System.Configuration does not support config files for libraries. -->
      <system.serviceModel>
        <services>
          <service name="WcfServiceForTFS.TFSEventSubscriber" behaviorConfiguration="WcfServiceLibrary1.Service1Behavior">
            <host>
              <baseAddresses>
                <add baseAddress="http://10.43.200.226:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
              </baseAddresses>
            </host>
            <endpoint address="" binding="basicHttpBinding" contract="WcfServiceForTFS.ITFSEventSubscriber">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="WcfServiceLibrary1.Service1Behavior">
              <!-- To avoid disclosing metadata information, 
              set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="True"/>
              <!-- To receive exception details in faults for debugging purposes, 
              set the value below to true.  Set to false before deployment 
              to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    
    

    Anyone have any suggestions on what is wrong?

    Thank you.

Answers

  • Monday, November 02, 2009 7:16 AMHongye SunMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi AnilCa,

    Thanks for your post and it's my pleasure to work with you again.

    The error message indicates that message is not in the correct format. It can be caused by incorrect binding. The correct binding is basicHttpBinding. 

    Please have a try of the following address to subscribe the event:

    BisSubscribe.exe /eventType WorkItemChangedEvent /address http://10.43.200.226:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/ /server TFS /deliveryType Soap 

    Please let me know if it works. Thanks.

     

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked As Answer byAnilCa Wednesday, November 04, 2009 4:46 PM
    •  

All Replies

  • Saturday, October 31, 2009 3:02 PMAnilCa Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I am noticing this error in the EventLog:

    TF53010: The following error has occurred in a Team Foundation component or extension:
    Date (UTC): 10/31/2009 2:57:40 PM
    Machine: TFS
    Application Domain: /LM/W3SVC/2064179709/ROOT/Services-2-129014732836818830
    Assembly: Microsoft.TeamFoundation.Server, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; v2.0.50727
    Process Details:
      Process Name: w3wp
      Process Id: 2836
      Thread Id: 4696
      Account name: NT AUTHORITY\NETWORK SERVICE

    Detailed Message: TF200034: A subscriber to a Team Foundation event (subscription ID=12) raised the following exception:
    Exception Message: The request failed with HTTP status 415: Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'.. (type WebException)

    Exception Stack Trace:    at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       at Microsoft.TeamFoundation.Server.NotificationClient.Notify(String eventXml, String tfsIdentityXml, SubscriptionInfo SubscriptionInfo)

     

  • Monday, November 02, 2009 7:16 AMHongye SunMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi AnilCa,

    Thanks for your post and it's my pleasure to work with you again.

    The error message indicates that message is not in the correct format. It can be caused by incorrect binding. The correct binding is basicHttpBinding. 

    Please have a try of the following address to subscribe the event:

    BisSubscribe.exe /eventType WorkItemChangedEvent /address http://10.43.200.226:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/ /server TFS /deliveryType Soap 

    Please let me know if it works. Thanks.

     

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked As Answer byAnilCa Wednesday, November 04, 2009 4:46 PM
    •