WCF测试程序
新建console application,添加服务引用,主要Address要到.svc部分。点击Go,找到对应服务后,点击OK。
双击ServiceReference2可以看到服务的名称,在Main函数中添加应用,如using ConsoleApplication2.ServiceReference2;调用服务中的函数
CallServiceClient client = new CallServiceClient();
client.方法名();
PS:需要在app文件中作如下设置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICallService" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="1111165536" maxBufferPoolSize="11111524288" maxReceivedMessageSize="1111165536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="111118192" maxArrayLength="111116384"
maxBytesPerRead="4096" maxNameTableCharCount="111116384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:3741/CallService.svc/Call"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICallService"
contract="ServiceReference1.ICallService" name="BasicHttpBinding_ICallService" />
</client>
</system.serviceModel>
</configuration>
除红色部分的设置外,其它非必须。
WCF的web.config文件中的设置:
<!--behaviorConfiguration="web"-->
<endpoint address="Call" binding="basicHttpBinding" contract="Call.ICallService" ></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
http绑定协议设置为basichttp。
程序发布时,endpoint改为:
<!--behaviorConfiguration="web"-->
<endpoint address="Call" binding="webHttpBinding" contract="Call.ICallService" behaviorConfiguration="web"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
并且要把basicHttpBinding节点改为webHttpBinding。