DCSIMG
WCF configuration - using the correct service name - Ido Flatow's Blog Veni Vidi Scripsi

Ido Flatow's Blog

Veni Vidi Scripsi

News

Have you heard me speak?
Powered
<style type='text/css' media='screen' id='sm_css'> #smix {overflow: visible;height: auto;border-radius: 10px;max-width: 250px;background-color: #323232;text-align: left;font-size: 12px;line-height: 16px;font-family:'Lucida Sans Unicode','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;-webkit-border-radius: 10px;-moz-border-radius: 10px;border-radius: 10px;} #smix a {color: #0056CC;text-decoration: none;} #smix .sm_head {color: #fff; line-height: 1em;font-size: 1.4em;padding: 10px;color: #fff;} #smix .sm_lanyard_wrapper {background-color: #fff;;clear: both;width: 97%;margin: 0 auto;margin-bottom: 0px;} #smix .sm_lanyard_content {padding: 7px;}#smix button.sm_rec, #smix a.sm_rec, #smix input[type=submit].sm_rec { padding: 6px 10px; -webkit-border-radius: 2px 2px;-moz-border-radius: 2px; border-radius: 2px; border: solid 1px rgb(153, 153, 153); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(255, 255, 255)), to(rgb(221, 221, 221))); color: #333; text-decoration: none; cursor: pointer; display: inline-block; text-align: center; text-shadow: 0px 1px 1px rgba(255,255,255,1); line-height: 1; }#smix .sm_rec:hover { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(248, 248, 248)), to(rgb(221, 221, 221))); }#smix .sm_rec:active { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(204, 204, 204)), to(rgb(221, 221, 221))); }#smix .sm_rec.medium { padding: 3px 7px; font-size: 13px; }#smix .sm_rec span.icon.thumbs_up {background-position: 0px 36px;vertical-align: text-top;display: inline-block;margin-right: 4px;height: 18px;width: 16px;background-image: url(http://speakermix.com/images/new/thumbsold.png);}#smix .sm_rec:hover span.icon.thumbs_up {background-position: 0px 18px;} #smix .sm_events {padding:2px 0px 4px 0px;} #smix .sm_section {font-size: 10px; border-bottom: 1px solid silver; margin-bottom: 6px;} #smix .sm_subline {font-size:120%;margin-top:4px;font-weight:bold} #smix .powered {text-align: right} #smix .powered img {margin: 7px} </style>
Sela Technology Center

Advertisement

WCF configuration - using the correct service name

In the last couple of weeks, I’ve been seeing several questions posted in the MSDN’s WCF forum about problems loading or consuming services, which eventually are found to be because of a misconfigured service name in the WCF configuration section (the <system.serviceModel>|<services> section).

This is an example of a thread that ended by fixing the namespace in the configuration:

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/348c1b12-c0fd-489c-8c5d-213cf4367565

And this thread was a bit trickier, but also ended with a “small” mismatch problem:

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/044fc42b-859b-442d-b2b1-c209682a1d39

So let me just recap the purpose of the name attribute in the service section – when a service host is opened for your service type (which you pass in the constructor), the host searches the configuration file for the configuration of the service. A configuration file can contain configuration for numerous services, so the host tries to find the matching <service> element by checking the name attribute. The name attribute therefore should be set to one of the following:

The service class name:

The name attribute should contain the full name of the service class, including its namespace, so for example, if your service class is called Service1, and it is defined under the namespace TestApplication.Services, then the service configuration will be:
<service name=”TestApplication.Services.Service1” ...>…</service>

A fixed name:

Some people don’t like the concept of writing the name of the class and the namespace in the configuration files, especially when a long namespace is used. Therefore, there is another option – you can set a special “configuration name” for your service, and use that name instead of the namespace+class technique.
To set a special configuration name for your service, decorate your service class with the ServiceBehavior attribute, and set the ConfigurationName property to a fixed name, for example “myService”:
[ServiceBehavior(ConfigurationName="myService")]
public class Service1 : IService1 {…}

Now, all you need to do in the configuration file, is to set the name attribute to myService:
<service name=”myService” ...>…</service>


Side note – you can also use the ConfigurationName parameter in the ServiceContract attribute in order to give the contract a fixed name, and use it in your endpoint configuration, instead of setting the contract attribute to the full name of the contract interface.

kick it on DotNetKicks.com Shout it

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# August 4, 2011 10:59 AM

Ido Flatow's Blog

Veni Vidi Scripsi

said:

This is the third post in the WCF 4.5 series, and we’re still in the subject of configuration, but this

# September 19, 2011 10:42 AM

Ido Flatow's Blog

Veni Vidi Scripsi

said:

This is the third post in the WCF 4.5 series, and we’re still in the subject of configuration, but this

# September 19, 2011 10:42 AM

Ido Flatow's Blog

Veni Vidi Scripsi

said:

This is the third post in the WCF 4.5 series, and we’re still in the subject of configuration, but this

# September 19, 2011 10:47 AM

[??????????????] ?????? ???????????? ?? WCF 4.5? ?????????????????? ???????????????????????? ?? intellisense ?? ???????????? ???????????????????????? « ahriman' lair said:

Pingback from  [??????????????] ?????? ???????????? ?? WCF 4.5? ?????????????????? ???????????????????????? ?? intellisense ?? ???????????? ???????????????????????? &laquo; ahriman&#039; lair

# January 30, 2012 10:14 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: