Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Tuesday, April 7, 2015

WCF REST CONFIGURATION FILE

Now the basic CRUD operations are mapped to the HTTP protocols in the following manner:
  • GET: This maps to the R(Retrieve) part of the CRUD operation. This will be used to retrieve the required data (representation of data) from the remote resource.
  • POST: This maps to the U(Update) part of the CRUD operation. This protocol will update the current representation of the data on the remote server.
  • PUT: This maps to the C(Create) part of the CRUD operation. This will create a new entry for the current data that is being sent to the server.
  • DELETE: This maps to the D(Delete) part of the CRUD operation. This will delete the specified data from the remote server.

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <protocolMapping>
      <add scheme="http" binding="webHttpBinding"/>
    </protocolMapping>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>

        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>  
 </configuration>
Use webHttpBinding (change default http port mapping to webHttpBinding)
<system.serviceModel>
    <protocolMapping>
        <add scheme="http" binding="webHttpBinding"/>
    </protocolMapping>
    <behaviors>

<system.serviceModel>
Specify webHttp End Point Behaviors
<system.serviceModel>
    -----
    </protocolMapping>
    <behaviors>
        <endpointBehaviors>
            <behavior>
                <webHttp />
            </behavior >
        </endpointBehaviors>
    <behaviors>
    ------
<system.serviceModel>


















Monday, October 21, 2013

WCF Multiple endpoint configuration

<?xml version="1.0"?>
<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<protocolMapping>
<add scheme="net.tcp" binding="netTcpbinding"/>
</protocolMapping>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
<netNamedPipeBinding>
<binding name="netNamedPipeBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None"></security>
</binding>
</netNamedPipeBinding>
<netTcpBinding>
<binding name="netTcpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<services>

<service name="MVKWCFService.ProductService" behaviorConfiguration="DefaultServiceBehavior">

<host>
<baseAddresses>
<add baseAddress="net.tcp://vishnu/MYNetTcpHost/"/>
<add baseAddress="http://vishnu/MYNetTcpHost/"/>
</baseAddresses>
</host>

<endpoint address="ProductService.svc" binding="wsHttpBinding"
  bindingConfiguration="wsHttpBinding" contract="MVKWCFService.IProductService"
  name="wsHttpBinding_IAuthenticationService" />

<endpoint address="ProductService.svc" binding="netTcpBinding"
  bindingConfiguration="netTcpBinding" contract="MVKWCFService.IProductService"
  name="netTcpBinding_IAuthenticationService" />
<!-- Service Endpoints -->
<endpoint address="httpmex" binding="mexHttpBinding" contract="IMetadataExchange" />

<endpoint address="tcpmex"                                                                
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">

<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="false"/>

<!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

</configuration>

Monday, July 8, 2013

WCF Endpoint and Binding by coding.


namespace ORS.SAMPLE.Base.Repository
{
    public class SAMPLEFactory : ISAMPLEServiceFactoryIDisposable
    {
        private bool _disposed;
        private ChannelFactory<ISAMPLESubject> factory;
        /// <summary>
        /// Constructor to initialize factory
        /// </summary>
        public SAMPLESubjectServiceFactory()
        {
          

Binding binding = null;
           
Uri address = null;
           

ProcessConfig.ResolveEndpoint("SAMPLESubjectServiceProxy.ISAMPLESubject"out address, out binding);
           

factory = new ChannelFactory<ISAMPLESubject>(binding, address.ToString());
        
   // Based on http://stackoverflow.com/questions/4812668/how-to-add-maxitemsinobjectgraph-programmatically-without-using-configuration-fi
 foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
            {
                var dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>();
                if (dataContractBehavior != null)
                {
                    dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                }
            }
        }
       


        /// <summary>
        /// Factory class
        /// </summary>
        /// <returns></returns>
        public ChannelFactory<IFuseSubject> Create()
        {
            return factory;
        }
       


        /// <summary>
        /// Close the factory
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
           {
                if (disposing)
                {
                    if (factory != null) factory.Close();
                }
                factory = null;
                _disposed = true;
            }
        }
    }
}

----------------------------------
----------------------------------

using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.ServiceModel.Configuration;

namespace ABIM.BusinessService.Home
{
    public static class ProcessConfig
    {
        private static System.ServiceModel.Configuration.BindingsSection GetBindingSection()
        {
            return ConfigurationManager.GetSection("system.serviceModel/bindings") as System.ServiceModel.Configuration.BindingsSection;
        }

        public static Binding ResolveBinding(string name)
        {
            System.ServiceModel.Configuration.BindingsSection section = GetBindingSection();

            foreach (var bindingCollection in section.BindingCollections)
            {
                for (int i = 0; i < bindingCollection.ConfiguredBindings.Count; i++)
                {
                    if (name.Equals(bindingCollection.ConfiguredBindings[i].Name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        var bindingElement = bindingCollection.ConfiguredBindings[i];
                        var binding = (Binding)Activator.CreateInstance(bindingCollection.BindingType);
                        binding.Name = bindingElement.Name;
                        bindingElement.ApplyConfiguration(binding);
                        return binding;
                    }
                }
            }
            return null;
        }

        private static ClientSection GetClientSection()
        {
            return ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
        }

        public static void ResolveEndpoint(string contract, out Uri host, out Binding binding)
        {
            host = null;
            binding = null;
            ClientSection clientSection = GetClientSection();
            ChannelEndpointElementCollection endpointCollection = clientSection.ElementInformation.Properties[string.Empty].Value as ChannelEndpointElementCollection;
            foreach (ChannelEndpointElement endpointElement in endpointCollection)
            {
                if (contract.Equals(endpointElement.Contract, StringComparison.CurrentCultureIgnoreCase))
                {
                    host = endpointElement.Address;
                    binding = ResolveBinding(endpointElement.BindingConfiguration);
                    return;
                }
            }
        }
    }

}









Thursday, July 5, 2012

WCF Service Configuration Issues



  1. To expose wcf service to other machine check whether fire wall is on or off in your system and client system ( while developing )

In Progress........
Simple things need to remember



Friday, April 29, 2011

WCF Workflow Service Application Enpoint configuration

 IService is a WCF Workflow Service Application Servicecontarct



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
        <services>
   <service name="xxxxxxx">
       <host>
           <baseAddresses>
               <add baseAddress="http://xxxxxx:1231/Configuration/"/>
           </baseAddresses>
       </host>
    <endpoint address="BDSIBUP301.xamlx"
     binding="wsHttpContextBinding" contract="IService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
   </service>
  </services>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
</configuration>