.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to pass behavior when creating a WCF Client?

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :WCF

I am trying to programatically set the behaviors for an endpoint for a WCF Service.


For example:


BasicHttpBinding binding = WCFBindingConfigSectionHandler.GetBasicHttpBinding(mConfig, mLogger);

EndPointAddress address = WCFBindingConfigSectionHandler.GetEndPointAddress(mConfig, mLogger);

EndPointBehaviorElement behaviors = WCFBindingConfigSectionHandler.GetEndPointBehavior(mConfig, mLogger);

binding.Security.Mode = BasicHttpSecurityMode.None

// call the WCF service.   Binding and Endpoint address set but How do I set the behavior.  The step above gathers the information and now I just need to set the behavior programatically.   Please help.

mpClient = new MeasurandProviderServiceClient(binding, address);

//The client offers a way to read the behavior but not set it.

Any ideas?


View Complete Post

More Related Resource Links

C# - Creating web client for automating user activity on a HTTPS site

I've been wracking my brain for a couple of weeks on this.  I need to create a web client (I don't want to use the webBrowser control because I need this to be as lightweight as possible) to log in to a secure web site, and then effectively click links and fill in fields to get the data that would normally be displayed in the web browser.  I'm then going to parse the data and perform other actions with it. I have been working with HttpWebRequest and HttpWebResponse and many permutations of suggestions I have found while Googling my issue, but I can't get rid of my problem:  Sometimes when I effictively click the ultimate link that I need to click to get to my data, I get what I am looking for.  However, MOST of the timel, I get a response page that tells me my connection timed out and that I need to log in again.  I have tried messing with cookies and such, but to no avail. I know it's good form to post my code, but it is so sloppy and screwed up right now from tweaking this and trying that, that I'd rather not take the approach of fixing what's there, rather I'd like to start with solid, clean code to begin with. Your help will be greatly appreciated. Thanks, ALo

Sign outgoing body from client with custom endpoing behavior defined in code

I'm trying to sign (and sign only) the body of every outgoing message that uses this custom endpoint behavior.  When I first created this it was for signing a custom SOAP header.  We are moving away from that and going to just sign the body.  We have some applications that have 10+ web service references.  We don't want to touch the reference.cs for anything.  Below is the code I had before for signing the custom soap header.  I'm trying to modify it to just sign the body.  My modified code is below, and the error I get. Private Class CustomHeaderBehavior Implements ServiceModel.Description.IEndpointBehavior Public Sub New() End Sub Private Sub AddBindingParameters( _ ByVal endpoint As ServiceModel.Description.ServiceEndpoint, _ ByVal bindingParameters As ServiceModel.Channels.BindingParameterCollection) _ Implements ServiceModel.Description.IEndpointBehavior.AddBindingParameters Dim body As New Xml.XmlQualifiedName("Body", "http://schemas.xmlsoap.org/soap/envelope/") Dim BodyMsgPartSpec As New ServiceModel.Security.MessagePartSpecification() BodyMsgPartSpec.IsBodyIncluded = True Dim requirements As ServiceModel.Security.ChannelProtectionRequirements = bindingParameters.Remove(Of ServiceModel.Security.ChannelProtectionRequirements)() requirements

Async Web Service behavior on client disconnect

Hi all, I was wondering what is the best way to detect client disconnect in the middle of an async web service call. I'm asusming that if a client disconnects while the server is still processing the async web method call, an exception will be thrown. First, I wonder if someone can confirm that this is the right assumption. If that's the case, then I was wondering where should I set up the SEH block to catch this exception. My gut tells me to set up the SEH block in side the delegate funciton, but I might be wrong. Also, what kind of an exception would I be getting if the client disconnects? Finally, if the SEH is set up in the delegate, what happens if a client disconnects in the tiny window before or after the delegate gets called? If someone can shed some light here I'd really appreciate it! Thanks, - K.  

Need suggestion's and guidelines for designing and creating WCF client channel pool

  What factor's should be considered for creating a WCF client channel pool? 1)Whether it is advisable to create a pool of pre-opened channel's?or create a new channel as an when needed?which one is expensive operation? 2)what should be the pool size? 3)how pool will support if concurrent request's are coming which use different binding's? 4)what should be channel lifetime? 5)If all the connection's in the pool are busy,whether we should wait till the free channel's are available in the pool or create new one's which is expensive?which one is better? if anybody is able to provide some usefull links it will be helpfull.

SQL client install was not creating the "ConnectTo" under msssqlserver\client

We detected the situation and found some info on it and there happened to be a workaround by either importing the key from another box or manually creating it. Then we can add in our alias’s, etc… we can now connect to a 32 bit SQL 2005 DB server.  Is MS aware of this problem and will there be a patch to fix to issue?  You can find more on the issue here: http://mossytips.blogspot.com/2008/10/installing-64-bit-moss-with-32-bit-sql.html  

Can a table name impact generating the service client when creating Service Reference?


I have a new WCF service I'm writing under VS2010 and IIS 7.5.  The service includes a table named Client.

When I built my test class and added the service reference, the first test was confirming the creation of the client.

My service reference did not generate any client that I could call .Open on!!!! I was wondering if it is due to that table name???

 Edited to add that I tested the service through the browser and it brings up the page and XAML fine.

Thanks for any assistance!

SQL SERVER 2008 TDE / Pass Private Key from Connecting Client


With TDE is it possible to pass the private key for an encrypted database from the client? 

I need to secure the database from the machine users.  They should only be able to access the database through my software, a C#/.Net app.  The server should only have the certificate and master key. 


How pass js array from client to server using jQuery?



i have an array on client side

var ResultArray = new Array();


for (i = 0; i < count; i++)



 var RowValue = { id: current_Id, value: current_Value };




than i send it to server

$.post( "Home/GetResult", { result: ResultArray }, null, "json" );

Before sending to server i can see all values in each item of my array 

But when i receive this one on server side, the answer is  "[object Object],[object Object],[object Object]"


public ActionResult GetResult(object[] result) // first way


object new_result = Request.Form["result"]; // second way

Can you explain me how should i send an array of objects from client side, and how should i receive this and detect each object in array on server side? Thanks.

Need help creating Secure Site that will require client certificate



I am trying to create a secure web service that will require certificate from clients. I'm not working with WCF, just a web service. This is what I did so far:

On the default web site, where I have other web sites that are not secured, I've configured one of the virtual directories in the following way: Directoy Security->Secure Communication -> Edit I've Tagged Require SSL, and Require client certificate. Then, I've created a Many to One Mapping rule that maps a certificate, by CN to a certain user account.

When I try to access the web site, with a client application (https://SERVERNAME/VIRTUALDIRECTORY/ASMXFILE.asmx) I get the following message :

"Unable to connect to the remote server"

Ofcourse I send a proper certificate.

What am I doing wrong?


Creating Functions and that pesky "Side-effecting behavior" error...



Well, I think we all at one point or another have been here, and frankly, I'm trying to figure a few things out with the nature of "Functions" in Transact-SQL (SQL Server 2008).  I am the type of programmer that is more programmer than SQL scripter, in the one fundamental nature that I don't like writing the same thing twice.  Usually because I forget.  You see a problem and want to solve it, but you can't exactly see the forest through the trees, and have to ask for help.  Someone, usually here, provides me with the insight I was looking for and I use it, walk away, 3 months later, I need the same help again.  No I'm not so crass as to repost the same question, but I have to look it up again.  So my theory, being as I said more the programmer than scripter, I wanted to create a function that just does it for me.  I add that function to the master database and voila, every time I need this <insert blah here> I can just run my function.

A perfect example is how I asked a while back how to create a Inline-randomizer, which basically would allow me to create a random number per line.  With the way caching and execution plans work in most SQL Engines, using a simple: Select *,Rand() from MyTable, will produce the exact same number each row for the Rand() function.  It was explained why, havi

How do I pass username/password credentials from php client to self-hosted wcf service?

I have a self-hosted wcf service that just adds 2 numbers and returns the value.  It works fine, but I am not sure how I can send the username and password through the php client, so it will validate against my CustomUserNamePasswordValidator.  Here is the implementation for the Add Method:

public class MathService : IMathService
    public double Add(double x, double y)
      return x + y;

Here is my current App.Config:

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

Creating your SharePoint Governance Plan

One of the most common questions that I get from prospects as I'm talking to them about the creation of a governance plan and process is what does it look like. In other words, there are materials available which describe what should be in a governance plan but there isn't a ton of guidance on what the process of creating a governance plan and process are.

Use jQuery and ASP.NET AJAX to build a client side Repeater

By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

Client Side Gridview Pagination using JQuery

I would like to show how to use Client Side Gridview Pagination using Jquery Table Pagination Plugin by using Ryan Zielke.

Use jQuery and ASP.NET AJAX to build a client side Repeater

By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

To that end, I'm going to walk you through these four steps to effectively implementing a client side Repeater, using ASP.NET AJAX and jQuery:

Creating Paging for a Repeater Control

A common question is "How do I implement paging within a Repeater?" Although the beauty of the Repeater control is its flexibility, you're on your own for building most functions. ASP.NET 2.0 has included some new controls that provide paging, as does the DataGrid in ASP.NET 1.1. However, this tip shows you how to roll your own paging for a simple data viewer.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend