Service webConfing
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_Default" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="154748364" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="WcfService.Test.ServiceBehavior"
name="WcfService.Test.LogTestService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Default" contract="WcfIService.Test.ILogTestService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService.Test.ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Web webconfig
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
ServiceClient 类
public class ServiceClient<TChannel> : IDisposable
{
private bool disposed;
// Fields
private TChannel channel;
// Properties
public TChannel Channel
{
get
{
return this.channel;
}
}
// Methods
public ServiceClient()
{
this.disposed = false;
string text1 = typeof(TChannel).Name;
this.Inite(text1);
}
public ServiceClient(string endpointName)
{
this.disposed = false;
this.Inite(endpointName);
}
/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
if (!this.disposed)
{
this.channelFactory.Close();
this.disposed = true;
}
}
private void Inite(string endpointName)
{
this.channelFactory = new ChannelFactory<TChannel>(endpointName);
this.channel = this.channelFactory.CreateChannel();
}
private ChannelFactory<TChannel> channelFactory;
}
方法调用
public static string ILogService = "WSHttpBinding_ILogTestService";
public static string AddLog()
{
using (ServiceClient<ILogTestService> Logtest = new ServiceClient<ILogTestService>(ILogService))
{
return Logtest.Channel.AddLog();
}
}