2009-12-12 156 views
2

對不起,我問了一些關於我不太瞭解的事情,但我一直在努力讓自己的工作變得有趣。訂閱TFS事件和WCF

因此,我有一個託管在IIS上的WCF服務,似乎正在工作,因爲我可以通過在瀏覽器中轉到http://servername/MyService.svc來在網絡上「看到」它。

這.SVC的樣子:

<% @ServiceHost Service="Foo.Bar" %> 

相關的代碼如下所示:

[ServiceContract(Namespace = "http://schemas.microsoft.com/TeamFoundation/2005/06Services/Notification/03")] 
    public interface IBar 
    { 
     [OperationContract(Action = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify", ReplyAction = "*")] 
     [XmlSerializerFormat(Style = OperationFormatStyle.Document)] 
     void Notify(string eventXml, string tfsIdentityXml); 
    } 

和:

public class Bar : IBar 
{ 
    public void Notify(string eventXml, string tfsIdentityXml) 
    { 
     // Just some test output to see if it worked 
     var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "tfs.txt"); 
     File.WriteAllText(path, tfsIdentityXml + eventXml); 
    } 
} 

這是所有已建成和隨之而來的.DLL投入bin目錄在IIS中的站點根目錄中。

我現在想通過bissubscribe.exe(或類似的方法)訂閱TFS簽入事件。我試着做類似的事情:

bissubscribe /eventType CheckinEvent 
    /address http://servername/MyService.svc 
    /deliveryType Soap 
    /server mytfsserver 

但沒事;它甚至不像有日誌活動。所以記住我對WCF一無所知,我做錯了什麼?我想象address參數是一回事;我不應該把它指向.svc嗎?

回答

1

突然出現的一點是,您有一種方法除了void之外不會返回任何內容。這些應該被標記爲WCF「單向」的方法:

[ServiceContract(Namespace = "http://schemas.microsoft.com/TeamFoundation/2005/06Services/Notification/03")] 
public interface IBar 
{ 
    [OperationContract(Action = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify", ReplyAction = "*", IsOneWay=true)] 
    [XmlSerializerFormat(Style = OperationFormatStyle.Document)] 
    void Notify(string eventXml, string tfsIdentityXml); 
} 

添加「IsOneWay = true」將您的[OperationContract]屬性。

除此之外,你的代碼中沒有任何明顯的錯誤,但要真正告訴我們,我們需要更多的配置信息來真正說明。首先嚐試IsOneWay=true,看看是否可以解決您的問題。

+0

好的,我可以做到 - 但比任何事情都好,我很好奇我的服務的「網址」是什麼。我知道這是一個愚蠢的問題,但是我發佈了一個(.svc)客戶端訪問它的正確方法嗎?或者通常如何做? – 2009-12-12 21:56:14

+1

啊好吧 - 抱歉,沒有捕捉到問題的部分:-)當在IIS中託管時,服務的URL由服務器(可能是一個端口),虛擬目錄和可能的子目錄定義* .svc文件的生命,以及svc文件本身的名稱和擴展名。所以它會像'http:// yourserver:8088/virtualdir/subdir/yourservice.svc' – 2009-12-12 22:10:00

+0

添加到那個URL你可能已經在服務配置文件中定義了任何可能的相對「地址」(web.config網站,在 ....節 – 2009-12-12 22:11:08

1

您的服務配置如何?特別是,它是否配置爲使用basicHttpBinding

嘗試創建一個客戶端來調用您的服務以確保它可以被調用。

然後,看看是否有一個來自TFS SDK的示例服務 - 請參閱是否可以讓示例工作。

+0

通知服務的TFS示例似乎指向一個.asmx文件,我沒有。我假設這不是WCF;相當於什麼? – 2009-12-12 21:57:25

+0

您是否有示例ASMX文件?這就是我希望您用來診斷問題所在的位置 – 2009-12-13 00:50:06

1

我能夠完成與以下這個連接:

[ServiceContract(Namespace = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03")] 
public interface ITeamSystemObserver : IObservable 
{ 
    [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); 
} 

注意你缺少的SubscriptionInfo參數。這裏是我的web.config:

<basicHttpBinding> 
    <binding name="TfsEventServiceBasic"> 
     <security mode="TransportCredentialOnly"> 
     <transport clientCredentialType="Ntlm" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
+0

謝謝您,我添加了這些更改,但我仍然從BisSubscribe.exe獲得HTTP 405錯誤,但對於某些理由 – 2009-12-14 18:44:19

2

TFS 2010和WCF 4.0配置如下所述...

方法簽名:

public void Notify(string eventXml) /* No SubscriptionInfo! */ 

Web配置:

<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"> 
     <assemblies> 
     <add assembly="Microsoft.TeamFoundation, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> 
     </assemblies> 
    </compilation> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="NotificationServiceBehavior" name="TF.CheckinListener.CheckinListener"> 
     <endpoint address="Notify" binding="wsHttpBinding" bindingConfiguration="noSecurity" contract="TF.CheckinListener.ICheckinListener" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="NotificationServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
    </binding> 
     <wsHttpBinding> 
     <binding name="noSecurity" maxBufferPoolSize="20000000" maxReceivedMessageSize="200000000"> 
     <readerQuotas maxStringContentLength="200000000" maxArrayLength="200000000" /> 
     <security mode="None" /> 
    </bindings> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

訂閱地址bissubscribe:

http://MachineName/VirtualDirectoryName/Service.svc/通知