2009-11-12 121 views
0

我有一個WCF服務庫與netTcpBinding。它的app.config如下:WCF服務庫 - 從控制檯應用程序撥打電話

<configuration> 
<system.serviceModel> 
<bindings> 
    <netTcpBinding> 
    <binding name="netTcp" maxBufferPoolSize="50000000" maxReceivedMessageSize="50000000"> 
     <readerQuotas maxDepth="500" maxStringContentLength="50000000" maxArrayLength="50000000" maxBytesPerRead="50000000" maxNameTableCharCount="50000000" /> 
     <security mode="None"></security> 
    </binding> 
    </netTcpBinding> 
</bindings> 

<services> 
    <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior" 
    name="ReportingComponentLibrary.TemplateReportService"> 
    <endpoint address="TemplateService" binding="netTcpBinding" bindingConfiguration="netTcp" 
     contract="ReportingComponentLibrary.ITemplateService"></endpoint> 
    <endpoint address="ReportService" binding="netTcpBinding" bindingConfiguration="netTcp" 
     contract="ReportingComponentLibrary.IReportService"/> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint> 

    <host> 
     <baseAddresses> 
     <add baseAddress="net.tcp://localhost:8001/TemplateReportService" /> 
     <add baseAddress ="http://localhost:8080/TemplateReportService" /> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 

<behaviors> 
    <serviceBehaviors> 
    <behavior name="ReportingComponentLibrary.TemplateServiceBehavior"> 
     <serviceMetadata httpGetEnabled="True"/> 
     <serviceDebug includeExceptionDetailInFaults="True" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
</system.serviceModel> 
</configuration> 

我想從控制檯應用程序調用它來測試目的。
據我所知,我可以通過添加服務引用或通過使用svcutil添加代理來調用。
但是,在這兩種情況下,我的服務需要啓動和運行(我使用WCF測試客戶端)

有從控制檯應用程序的任何其他方式我可以打電話和測試服務的方法?

回答

0

出於測試目的,您可以使用WcfSvcHost.exe託管您的WCF服務。要調用它的方法,你不需要你可以使用的客戶端WcfTestClient.exe

+0

感謝您的回覆。我一直只使用WCF Test Client來啓動和運行我的服務,以便上述兩種方法可以工作。在某些地方,我也看到了使用ServiceHost的例子,儘管我不確定它如何在控制檯應用程序中工作。 – iniki 2009-11-12 11:01:14

+0

只需再注意一點,我不能直接使用WCF Test Client,因爲它不會採用的配置設置,我需要在每個實例化中更改它們。所以正在尋找其他方式來主辦它。 – iniki 2009-11-12 11:50:40

0

這些是我能想到的唯一方法。不過,我的web服務模塊通常很簡單,只需調用另一個.NET模塊即可。你可以從你的控制檯應用程序進行相同的調用,或者如果這個調用暴露得太多,就創建另一個.NET DLL,以便爲控制檯應用程序公開相同的調用。它不會讓你測試本身的「網絡服務」(用於承載等),但你仍然在測試功能。