2009-11-12 127 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,以便为控制台应用程序公开相同的调用。它不会让你测试本身的“网络服务”(用于承载等),但你仍然在测试功能。