Click here to Skip to main content
15,885,216 members
Articles / Web Development / ASP.NET

CustomBinding on Service Reference Results in TransportBindingElement Error

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
31 Oct 2011CPOL2 min read 22K   2
CustomBinding on Service Reference Results in TransportBindingElement Error

I’m coding an ASP.NET MVC 3 web site in Visual Studio 2010. I added a service reference to a SOAP 1.2 version of a web service and started updating my code (I was using a SOAP 1.1 endpoint previously).

Unfortunately, the switchover wasn’t as clean as I had hoped. The first method I changed resulted in an error, even on a call that appeared identical to the previous version. The error message I received was:

The CustomBinding on the ServiceEndpoint with contract 'SubscriberServices' lacks a TransportBindingElement. Every binding must have at least one binding element that derives from TransportBindingElement.

…which looked like this:

image

For the quick fix, head to the end of this article. Keep reading if you want to know what’s going on.

What Was Going On?

The two things that gave me the strongest clues were “CustomBinding” and “TransportBindingElement”, but for different reasons. CustomBinding was a little unexpected as the service was added via HTTP. I guess I always assumed that it would be using an HTTP binding? The other piece suggested a derivative of the TransportBindingElement, which according to MSDN is an abstract base class.

Off to Our Config File

Actually, at this point, I wanted less noise, so I quickly created a console app and added references to both services. The differences were, at this point, fairly obvious. The 1.1 version of the service was using a basicHttpBinding element (which I was expecting), whereas the 1.2 service was using a custom binding:

image

So, what we’re looking at is trying to get the custom binding to know which transport we want to use. This is something that is implicit in the basicHttpBinding but needs to be explicitly set for customBindings.

The Fix

Following the links on the TransportBindingElement will lead us to the httpTransportbindingElement, which has both code and config file samples. Adding a short and simple section to the binding did the trick; all I needed was an httpTransport element in the customBinding\binding element. The updated config section looked like this with the MSDN sample config injected:

image

Further reading shows that all the properties set in the MSDN example are actually all defaults, which means that our httpTransport element can simply be reduced to a single, self-closing tag:

image

Great!

Quick Recap

So, in short, if you’re using a SOAP 1.2 service reference, or any service reference that requires the use of a custom binding, make sure you’ve added a TransportBindingElement (such as httpTransport) to your config file or in your code.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Canada Canada
For almost 30 years I have been working with computers, learning a myriad of languages and participating in various computing environments.

Though I have been mentoring other developers for the last decade, I have recently found a strong interest in writing and am learning to translate the fun of in-person teaching to something I can get into article form.

I enjoy following technology trends, new gadgets and trying to guess where innovation will lead us next (I'm kinda holding out for a robot-served utopia, but willing to submit to our future robot leaders).

I am a guy who is passionate about my faith, my family and a cure for Juvenile Diabetes (my son lives with this disease).

Comments and Discussions

 
QuestioncustomBinding programmatically Pin
Abdul Rahman El Habboub18-Jan-22 6:02
Abdul Rahman El Habboub18-Jan-22 6:02 
QuestionCustomBinding on Service Reference Results in TransportBindingElement Error Pin
Yogesh Sonawane23-Dec-14 20:37
Yogesh Sonawane23-Dec-14 20:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.