Free Jobs

Dot Net Forums: ASPNET (77) C#.NET (39) VB.NET (8) AJAX (21) Silver Light (1) WCF (10) WPF (1) WWF (1) .NET 3.5 (3) SQL SERVER (38) Other (3)

Topic: How To Call WCF service SampleService from ASP.NET c# Project

To get the Posted Questions details daily in your mail Click Here

Share this Post on Facebook/Twitter/Orkut Bookmark and Share

User: rajiv100 Post Date: 04 May 2012 01:16

How To Call WCF service SampleService from ASP.NET c# Project

Main Content:

Add the proxy file SampleService.cs

after creating proxy folder in root of c# project.

Suppose namespave in proxy is its namespace is Company.Project.Module.ApplicationHost.Proxy

Suppose you have to call the SampleService from SampleCodeBehine.cs file

add the below line in the using block.

using Sample_Proxy = Company.Project.Module.ApplicationHost.Proxy;

Note that in proxy there will be one class where you

will have all the service methods like as below

public partial class SampleServiceClient

Sample_Proxy.SampleServiceClient Sampleclient = null;

Sample_Proxy.SampleMethodResponse SampleMethod_resp = new Sample_Proxy.SampleMethodResponse();

Sample_Proxy.SampleMethodRequest SampleMethod_Req = new Sample_Proxy.SampleMethodRequest();

Sampleclient = new


bConnection = Sampleclient.SampleMethod(healthcheck_Req);

where SampleMethod is the method of SampleService.

iN THE APP.CONFIG OF SampleProject

<?xml version="1.0" encoding="utf-8" ?>





                <binding name="BasicHttpBinding_ISampleService"

                    closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"

                    sendTimeout="00:01:30" allowCookies="false" bypassProxyOnLocal="false"

                    hostNameComparisonMode="StrongWildcard" maxBufferSize="65536"

                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"

                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"


                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />

                    <security mode="Transport">

                        <transport clientCredentialType="None" proxyCredentialType="None"

                            realm="" />

                        <message clientCredentialType="UserName" algorithmSuite="Default" />









                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleService"


name="BasicHttpBinding_ISampleService" />







This way we can call WCF service SampleService from ASP.NET c# Project

About Writer:
Hi,I am .NET Developer From Bangaloret

Writer's Link:

Writer's Email:

  • User: manishav3388 Post Date:   22 May 2012 12:54
    WEB(TestPage.aspx.cs)Application Host(Having .svc file)--> -->Company.Services.Services\SampleService.cs -- >BusinessLayer -->DataLayer --OtherService or Database)

    NewOrder method calls GetEndPoint ,this method will return secondary end point if failover has happend.

    GetEndPoint method will decide the failover from the timestap value from cache

    cacheFailoverTimeStamp = CoordinationContext.Current.Cache[Constants.PaymentGatewayFailoverTimestamp]

    This timestamp in cache will be set by method SetFailover that is called

    after exception other than time out exception happens and retry happen two times

    and then a method is called which calls sets failover.


    In the TestPage.aspx.cs we catch




    In DataLayer.cs we catch

    TimeoutException --If one time time out happens we call once more using a global bool variable

    Exception -- If general

  • User: manishav3388 Post Date:   22 May 2012 13:00
    In DataLayer.cs we catch

    TimeoutException --If one time time out happens we call once more using a global bool variable

    Exception -- If general exception is caught

                 First we convert it into WCF App exception

                 Then see if it matches a payment gateway known error we go for retry depending on error code

                 other wise we throw ex


                 if the error code is for retry then retry happen two times

                 and then failover happens to secondary end point.


  • User: manishav3388 Post Date:   13 Jun 2012 23:50

    Use Username Authentication with Transport Security in WCF Calling from Windows Forms

    Click the Security tab and then set the Mode attribute to Transport.

    Set the TransportClientCredentialType to None by selecting this option from the drop-down list.

    Authentication will be done by the HTTP module in ASP.NET.

    For user name and password security

    you need to send the user name and password in request object

    attribute and then match it with pre set (probably in config)

    user name password value

    if it does not match then send a fault exception back

    with particular error code in response object

    that will ultimately mean to client as failed authentication.

    In client aslo username and password should be read from config.

    There are three class in proxy




     AuthorizationRq authInputReq = new AuthorizationR

  • User: manishav3388 Post Date:   13 Jun 2012 23:54
    There are three class in proxy




     AuthorizationRq authInputReq = new AuthorizationRq();

    populate the filed of authInputReq

    SampleServiceClient target = new SampleServiceClient(SecurityScenario.Custom, "BasicHttpBinding_ISampleServiceClient");

    AuthorizationRs authResponse = target.AuthorizePayment(authInputReq);


Post Comment

Similar Articles Top ArticlesLatest Articles Other Articles by this Author Copyright © 2009-2011 | All Rights Reserved
All content of this website is protected by copyright laws and should not be reproduced in any form or by any means without written permission
(Best viewed in IE 8.0+ or Firefox 3.0+ at resolution of 1024 * 768 or higher)