Using WCF service without Config
When you use WCF normally you need to add the system.serviceModel elements to the Solutions Primary project config file. There are many scenarios where this can not be done or you would prefer not too!
I've create a single class so I can reference the required logic, anywhere within my solution. Each element is broken down into its own methods

Basic Binding
This is a simple method, which will create and return a basic binding object.
You can add more elements to the binding.


public static BasicHttpBinding SetBasicBinding()
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.TextEncoding = System.Text.Encoding.UTF8;

EXAMPLE - You can add the below code to allow larger files and longer timeout than the default value
The below items can be added to the WCF solution config file as well. (Source config alteration)

binding.AllowCookies = true;
binding.ReceiveTimeout = new TimeSpan(0,30,00);
binding.SendTimeout = new TimeSpan(0, 30, 00);
binding.MaxBufferPoolSize = 2147483647;
binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
binding.ReaderQuotas.MaxDepth = 34;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
return binding;
}


Secure Binding
Within the WCF logic, if you want to use HTTPS you really need to make sure you use the Secure binding not basic

public static BasicHttpSecurity SetSecureBinding()
{
BasicHttpSecurity binding = new BasicHttpSecurity();
binding.Mode = BasicHttpSecurityMode.Transport;
return binding;
}



End point address
This is a simple method, which will create and return a endpoint object, with the address you have provided.

public static EndpointAddress SetEndpoint(string url)
{
return new EndpointAddress(url);
}



Using the New methods
Now when you call the WCF you reference the new method and you wont need to the config entry in the primary project.
You will need the references within the sub project that contains the WCF, so you can update your service when needed

**WCFReferance - This is the name of the Reference you have created for the WCF Service reference


private void queryStatus(int transactionId)
{

using (WCFReferance.StatusClient wsf = new WCFReferance.StatusClient(Utilities.WCFCallBuilder.SetBasicBinding(), Utilities.WCFCallBuilder.SetEndpoint(BusinessObjects.EHC.Queries.Extended.RecordText1(BusinessObjects.EHC.ENUMS.Extended.BackEndStatusURL))))
{
var dataClass = wsf.Latest(transactionId);

}//END using (BackendStatusWCF.StatusClient wsf = new BackendStatusWCF.StatusClient())
}


Source Config file
If you know your WCF is always needs binding information, which will be above the default value.
You can alter the WCF config, by adding the below below lines into the basicHttpBinding node under system.serviceModel


<binding maxReceivedMessageSize="2147483647" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">;
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483646" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647">;
</binding>
Created: 12/10/2016 Total Comment: 0

Comments

(Not Displayed)
Human validation
Enter 2687 number, before submitting to confirm your human
[Home] [All Blogs] [Contact] [Me]