wcf 例子

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();
             }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值