<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>WCF</title>
        <link>http://agilior.pt/blogs/bruno.camara/category/1.aspx</link>
        <description>WCF</description>
        <language>en-US</language>
        <copyright>BFC</copyright>
        <managingEditor>bruno.camara@agilior.pt</managingEditor>
        <generator>Subtext Version 1.9.0.27</generator>
        <item>
            <title>WCF Service Hosted in IIS with Integrated Authentication</title>
            <link>http://agilior.pt/blogs/bruno.camara/archive/2008/02/19/3721.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt; &lt;p&gt;Recently we developed a WCF service, which had to be hosted in IIS. This service must run under the credentials of the user calling the service, so we used Integrated Authentication with Impersonation. Even the service was hosted in IIS, we were not using ASP.Net compatibility mode, so the WCF was responsible to do all the work related to authentication and impersonation. &lt;/p&gt; &lt;p&gt;At the client, we generated the proxy using Add Service Reference (to use WCF at client side), and we started our tests. Here is the configuration used at the client&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:e444b482-5932-44c3-a7df-34263105c526" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;pre style="background-color:White;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #FF00FF; "&gt;xml version="1.0" encoding="utf-8" &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;?&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;configuration&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;system&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;.serviceModel&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;bindings&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
            &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;basicHttpBinding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;binding &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;name&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="BasicHttpBinding_IMyService"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; closeTimeout&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="00:01:00"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                    openTimeout&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="00:01:00"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; receiveTimeout&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="00:10:00"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; sendTimeout&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="00:01:00"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                    allowCookies&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="false"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; bypassProxyOnLocal&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="false"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; hostNameComparisonMode&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="StrongWildcard"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                    maxBufferSize&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="65536"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; maxBufferPoolSize&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="524288"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; maxReceivedMessageSize&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="65536"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                    messageEncoding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="Text"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; textEncoding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="utf-8"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; transferMode&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="Buffered"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                    useDefaultWebProxy&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="true"&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;readerQuotas &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;maxDepth&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="32"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; maxStringContentLength&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="8192"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; maxArrayLength&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="16384"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                        maxBytesPerRead&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="4096"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; maxNameTableCharCount&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="16384"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;security &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;mode&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="TransportCredentialOnly"&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;transport &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;clientCredentialType&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="Ntlm"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; proxyCredentialType&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="None"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                            realm&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;=""&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;message &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;clientCredentialType&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="UserName"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; algorithmSuite&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="Default"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;security&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;binding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
            &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;basicHttpBinding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;bindings&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;client&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
            &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;endpoint &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;address&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="http://myserver/webServices/MyService.svc"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                binding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="basicHttpBinding"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; bindingConfiguration&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="BasicHttpBinding_IMyService"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                contract&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="TestConsole.mySvc.IMyService"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; name&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="BasicHttpBinding_IMyService"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;client&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;configuration&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Our first test passed with success. However, after some resets in IIS we got un exception when calling the service from the client&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Could not load file or assembly 'MyAssembly, Version=&lt;/strong&gt;&lt;a href="http://1.0.0.0"&gt;&lt;strong&gt;1.0.0.0&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;, Culture=neutral, PublicKeyToken=fa47a5aeac7aa410' or one of its dependencies. Access is denied.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Without understanding the source and the cause of this random error, we began our research. We tried to change ACLs, we tried to change settings on the Application Pool, we tried everything you can imagine, and after a few days of trial and error, we discovered the pattern of the error. So, we got success on the service call after cleaning all the Temporary ASP.Net File and resetting the IIS. In this condition the service ran ok, until the next compilation, maybe caused by a modification in the web.config file. After the new compilation we got the exception again. I almost quit hosting my service in IIS, and change to a self-hosted service, using a windows service. However, before quit, I decided to ask for help to one of the Portuguese WCF Gurus, &lt;a href="http://www.arquitecturadesoftware.org/blogs/antoniocruz/"&gt;António Cruz&lt;/a&gt;. A few hours later, António call me, and told me that the problem was in the client side, because we were not specifying the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.servicemodel.security.windowsclientcredential.allowedimpersonationlevel.aspx"&gt;allowed impersonation level&lt;/a&gt;, and the default is &lt;a href="http://msdn2.microsoft.com/en-us/library/system.security.principal.tokenimpersonationlevel.aspx"&gt;Identification&lt;/a&gt;,which means (pasting from documentation)&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;em&gt;The server process can obtain information about the client, such as security identifiers and privileges, but it cannot impersonate the client. This is useful for servers that export their own objects, for example, database products that export tables and views. Using the retrieved client-security information, the server can make access-validation decisions without being able to use other services that are using the client's security context.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;António told me to use the level &lt;a href="http://msdn2.microsoft.com/en-us/library/system.security.principal.tokenimpersonationlevel.aspx"&gt;Impersonation&lt;/a&gt; instead, which means (pasting again)&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;em&gt;The server process can impersonate the client's security context on its local system. The server cannot impersonate the client on remote systems.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt; &lt;/p&gt;
&lt;p&gt;To do this we had to specify a behavior. Here is the new configuration file&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:9fd6b532-d8c4-43b0-878c-a599a11deda6" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; width: 834px; padding-top: 0px"&gt;&lt;pre style="background-color:White;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #FF00FF; "&gt;xml version="1.0" encoding="utf-8" &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;?&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;configuration&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;system&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;.serviceModel&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;bindings&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
            &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;basicHttpBinding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;binding &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;name&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="BasicHttpBinding_IMyService"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; closeTimeout&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="00:01:00"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                    openTimeout&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="00:01:00"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; receiveTimeout&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="00:10:00"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; sendTimeout&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="00:01:00"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                    allowCookies&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="false"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; bypassProxyOnLocal&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="false"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; hostNameComparisonMode&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="StrongWildcard"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                    maxBufferSize&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="65536"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; maxBufferPoolSize&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="524288"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; maxReceivedMessageSize&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="65536"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                    messageEncoding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="Text"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; textEncoding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="utf-8"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; transferMode&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="Buffered"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                    useDefaultWebProxy&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="true"&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;readerQuotas &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;maxDepth&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="32"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; maxStringContentLength&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="8192"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; maxArrayLength&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="16384"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                        maxBytesPerRead&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="4096"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; maxNameTableCharCount&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="16384"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;security &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;mode&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="TransportCredentialOnly"&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;transport &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;clientCredentialType&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="Ntlm"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; proxyCredentialType&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="None"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                            realm&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;=""&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;message &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;clientCredentialType&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="UserName"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; algorithmSuite&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="Default"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;security&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;binding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
            &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;basicHttpBinding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;bindings&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;client&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
            &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;endpoint &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;address&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="http://ag-bfcamara/webServices/MyService.svc"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                binding&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="basicHttpBinding"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;     bindingConfiguration&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="BasicHttpBinding_IMyService"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
                contract&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="TestConsole.mySvc.IMyService"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; name&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="BasicHttpBinding_IMyService"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt;
               behaviorConfiguration&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="ImpersonationBehavior"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;client&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;behaviors&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
           &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;endpointBehaviors&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
              &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;behavior &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;name&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="ImpersonationBehavior"&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                 &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;clientCredentials&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                      &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000; "&gt;windows &lt;/span&gt;&lt;span style="color: #FF0000; "&gt;allowedImpersonationLevel&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;="Impersonation"&lt;/span&gt;&lt;span style="color: #FF0000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
                 &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;clientCredentials&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
              &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;behavior&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
           &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;endpointBehaviors&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;behaviors&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000; "&gt;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000; "&gt;configuration&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;With this configuration we eliminate the strange behaviour we had before and everything is now ok. And this security feature makes sense, since the client has the right to specify what kind of impersonation the service can do. However, when using Identification level (which is the default), why the service runs ok if we delete the temporary ASP.Net files and reset IIS? It seems there is a special condition which makes the service run without problem, at least until the next compilation. Very strange!&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;From all Agilior Team, a special thanks to António Cruz.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;BFC&lt;/p&gt;&lt;img src="http://agilior.pt/blogs/bruno.camara/aggbug/3721.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>BFC</dc:creator>
            <guid>http://agilior.pt/blogs/bruno.camara/archive/2008/02/19/3721.aspx</guid>
            <pubDate>Tue, 19 Feb 2008 11:26:25 GMT</pubDate>
            <wfw:comment>http://agilior.pt/blogs/bruno.camara/comments/3721.aspx</wfw:comment>
            <comments>http://agilior.pt/blogs/bruno.camara/archive/2008/02/19/3721.aspx#feedback</comments>
            <slash:comments>13</slash:comments>
            <wfw:commentRss>http://agilior.pt/blogs/bruno.camara/comments/commentRss/3721.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Xsd annotations in WCF</title>
            <link>http://agilior.pt/blogs/bruno.camara/archive/2006/10/01/6.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;
&lt;p style="text-align: justify;"&gt; &lt;br /&gt;
This post has the goal to explain how it is possible to make Xsd annotations in the Wsdl generated by Windows Communication Foundation (the version we are using in our project is WinFx 3.0 Beta 2 Go-Live).&lt;br /&gt;
Unfortunately, Indigo does not allow to specify an annotation in the DataMember attribute. So, we can't do this,&lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:45d7e498-6625-47de-b7d9-05a8405eb8cb" class="wlWriterSmartContent"&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[DataContract]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; MyDataContract&lt;br /&gt;{&lt;br /&gt;    [DataMember(XsdAnnotation&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;MyAnnotation&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)]&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; MyDataMember;&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;What we want is something like this, &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:b9c3a912-3baa-42cc-92be-d0c35e921cef" class="wlWriterSmartContent"&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; [DataContract] &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; MyDataContract&lt;br /&gt;{&lt;br /&gt;    [DataMember]&lt;br /&gt;    [DataMemberAnnotation(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;MyAnnotation&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)]&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; MyDataMember;&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p style="text-align: justify;"&gt;and in the generated Wsdl we expect to have in our schema an Xsd annotation associated with the element MyDataMember. &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;p style="text-align: justify;"&gt;First of all we must create our attribute, &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;p style="text-align: justify;"&gt; &lt;/p&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:397cb0db-5740-479c-b4c4-e124085636d7" class="wlWriterSmartContent"&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    [AttributeUsage(AttributeTargets.Field &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;|&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; AttributeTargets.Property, Inherited &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;br /&gt;AllowMultiple &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)]&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataMemberAnnotationAttribute : Attribute&lt;br /&gt;    {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; m_Annotation;&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataMemberAnnotationAttribute(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; annotation)&lt;br /&gt;        {&lt;br /&gt;            m_Annotation &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; annotation;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Annotation&lt;br /&gt;        {&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;get&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;             &lt;br /&gt;            {                 &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&lt;br /&gt;                return&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; m_Annotation;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p style="text-align: justify;"&gt;Let me say that the solution we present in this post required some time using Lutz Roeder's .NET Reflector to understand the Wsdl generation process of the  DataContractSerializer class. The class responsible for all this process is the DataContractSerializerOperationBehavior in the namespace System.ServiceModel. &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;p style="text-align: justify;"&gt;It is very interesting to see that the internals of this process are already prepared to make Xsd annotations, however there is no simple way to do it. Maybe in the final version we have this feature simplified, who knows. &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;p style="text-align: justify;"&gt;Basically, what we've to do is inherit from DataContractSerializerOperationBehavior and, in the new class created, tweak the wsdl generation. We're just intercepting the wsdl generation, so we've to implement the interface IWsdlExportExtension&lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:559260a3-0650-4ce3-8dc7-22d671e498c4" class="wlWriterSmartContent"&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractWithXsdAnnotationsSerializerOperationBehavior: &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    DataContractSerializerOperationBehavior, IWsdlExportExtension&lt;br /&gt;{&lt;br /&gt;    ...&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)&lt;br /&gt;        {&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)&lt;br /&gt;        {&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    ...&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p style="text-align: justify;"&gt;We've only to focus on this two methods to manipulate the wsdl generation. The simplest solution is to get from WsdlExporter the object responsible for the schema generation, which is an instance of the class XsdDataContractExporter, and set the ExportOptions property. One of the properties of the ExportOptions we can set is DataContractSurrogate, which have to implement the interface IDataContractSurrogate. This interface allow us to extend the generated schema. The IDataContractSurrogate is very simple, since we just want to change the export of schema.&lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:406c2254-8759-4a13-ab36-b9459952d8e5" class="wlWriterSmartContent"&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractXsdAnnotationSurrogate : IDataContractSurrogate&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    {&lt;br /&gt;        ...&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; GetCustomDataToExport(MemberInfo memberInfo, Type dataContractType)&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[] dataMemberAnnotations &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;br /&gt;                 memberInfo.GetCustomAttributes(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(DataMemberAnnotationAttribute), &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (dataMemberAnnotations &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;!=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; dataMemberAnnotations.Length &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;br /&gt;            {&lt;br /&gt;                DataMemberAnnotationAttribute annotation &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;br /&gt;                    dataMemberAnnotations[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;] &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataMemberAnnotationAttribute;&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; annotation.Annotation;&lt;br /&gt;            }&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;        ...&lt;br /&gt;    }&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;br /&gt;
 &lt;/p&gt;
&lt;p style="text-align: justify;"&gt;To get access to the XsdDataContractExporter, and change the IDataContractSurrogate to use, we implemented an helper method in our behavior&lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:d76ad803-28c8-420b-8857-d2f88664ec13" class="wlWriterSmartContent"&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractWithXsdAnnotationsSerializerOperationBehavior: &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;   DataContractSerializerOperationBehavior, IWsdlExportExtension&lt;br /&gt;{&lt;br /&gt;        ...&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; InitXsdDataContractExporter(WsdlExporter exporter)&lt;br /&gt;        {&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; xsdDataContractExporterObj;&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;exporter.State.TryGetValue(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(XsdDataContractExporter), &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&lt;br /&gt;                  out&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; xsdDataContractExporterObj))&lt;br /&gt;            {&lt;br /&gt;                xsdDataContractExporterObj &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; XsdDataContractExporter(exporter.GeneratedXmlSchemas);&lt;br /&gt;                exporter.State.Add(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(XsdDataContractExporter), xsdDataContractExporterObj);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            XsdDataContractExporter xsdDataContractExporter &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;br /&gt;               xsdDataContractExporterObj &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; XsdDataContractExporter;&lt;br /&gt;&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (xsdDataContractExporter.Options &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;==&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;br /&gt;            {&lt;br /&gt;                xsdDataContractExporter.Options &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ExportOptions();&lt;br /&gt;                xsdDataContractExporter.Options.DataContractSurrogate &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&lt;br /&gt;                    new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractXsdAnnotationSurrogate();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        ...&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="text-align: justify;"&gt;Next, we just need to invoke this method before the export of the wsdl begins  &lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:9d55eec8-5220-4c09-b4fc-1763c2bd0cf7" class="wlWriterSmartContent"&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractWithXsdAnnotationsSerializerOperationBehavior: &lt;br /&gt;    DataContractSerializerOperationBehavior, IWsdlExportExtension&lt;br /&gt;{&lt;br /&gt;         ...&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)&lt;br /&gt;        {&lt;br /&gt;            InitXsdDataContractExporter(exporter);&lt;br /&gt;             ...&lt;br /&gt;    &lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)&lt;br /&gt;        {&lt;br /&gt;            InitXsdDataContractExporter(exporter);&lt;br /&gt;             ...&lt;br /&gt;        }&lt;br /&gt;        ...&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p style="text-align: justify;"&gt;Now that we have the XsdDataContractExporter as we wish, with our custom IDataContractSurrogate, we can begin the wsdl generation. Unfortunately the methods ExportContract and ExportEndpoint, in our base class, are not public or protected so we can't do &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;p style="text-align: justify;"&gt;base.ExportContract(exporter, context); &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;p style="text-align: justify;"&gt;or &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;p style="text-align: justify;"&gt;base.ExportEndpoint(exporter, context); &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;p style="text-align: justify;"&gt;The less elegant part of the solution is the need to use reflection for the call, &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;p style="text-align: justify;"&gt;typeof(IWsdlExportExtension).InvokeMember("ExportContract", BindingFlags.InvokeMethod, null, this, new object[] { exporter, context }); &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;p style="text-align: justify;"&gt; &lt;/p&gt;
&lt;p style="text-align: justify;"&gt;However, this does not work either, because we want to invoke the method in the base class and not in our instance. This complicates a little bit the solution because we need to have a reference to the original instance of the DataContractSerializerOperationBehavior. To do that, we must have another OperationBehavior which removes from the behaviors collection the DataContractSerializerOperationBehavior, and gives the reference of the instance that was removed to our DataContractWithXsdAnnotationsSerializerOperationBehavior, which must be added to the behaviors collection. Here it is, &lt;/p&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:8c73f086-353c-416e-9d69-c26a1aec4bc0" class="wlWriterSmartContent"&gt;
&lt;div style="text-align: justify;"&gt; &lt;/div&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ExportWsdlWithXsdAnnotationsOperationBehavior: Attribute, IOperationBehavior&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    {&lt;br /&gt;    ...&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ApplyDispatchBehavior(OperationDescription description, &lt;br /&gt;             System.ServiceModel.Dispatcher.DispatchOperation dispatch)&lt;br /&gt;        {&lt;br /&gt;            &lt;br /&gt;            DataContractSerializerOperationBehavior dataContractSerializerOperationBehavior &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;br /&gt;                description.Behaviors.Find&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;DataContractSerializerOperationBehavior&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;();&lt;br /&gt;            &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;//&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;Remove the default operation behavior and add &lt;br /&gt;            //DataContractWithXsdAnnotationsSerializerOperationBehavior&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;            &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; (dataContractSerializerOperationBehavior &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;!=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;br /&gt;            {&lt;br /&gt;                description.Behaviors.Remove(dataContractSerializerOperationBehavior);&lt;br /&gt;                description.Behaviors.Add(&lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractWithXsdAnnotationsSerializerOperationBehavior(&lt;br /&gt;                    dataContractSerializerOperationBehavior, description, &lt;br /&gt;                    dataContractSerializerOperationBehavior.DataContractFormatAttribute));&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;        ...&lt;br /&gt;    }&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;br /&gt;
&lt;/p&gt;
&lt;p style="text-align: justify;"&gt;In DataContractWithXsdAnnotationsSerializerOperationBehavior we must receive the original&lt;br /&gt;
DataContractSerializerOperationBehavior in our constructors&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:12c2e2ea-4c39-452b-bd92-86a7cbd5c79b" class="wlWriterSmartContent"&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractWithAnnotationsSerializerOperationBehavior : &lt;br /&gt;    DataContractSerializerOperationBehavior, IWsdlExportExtension&lt;br /&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractSerializerOperationBehavior m_DataContractSerializerOperationBehavior;&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractWithXsdAnnotationsSerializerOperationBehavior(&lt;br /&gt;            DataContractSerializerOperationBehavior originalSerializer, &lt;br /&gt;            OperationDescription operation)&lt;br /&gt;            : &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(operation)&lt;br /&gt;        {&lt;br /&gt;            m_DataContractSerializerOperationBehavior &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; originalSerializer;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractWithXsdAnnotationsSerializerOperationBehavior(&lt;br /&gt;          DataContractSerializerOperationBehavior originalSerializer, &lt;br /&gt;          OperationDescription operation,  &lt;br /&gt;          DataContractFormatAttribute dataContractFormatAttribute)&lt;br /&gt;            : &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(operation, dataContractFormatAttribute)&lt;br /&gt;        {&lt;br /&gt;            m_DataContractSerializerOperationBehavior &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; originalSerializer;&lt;br /&gt;        }&lt;br /&gt;        ...&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="text-align: justify;"&gt;Finally, ExportContract and ExportEndpoint will look like this,  &lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:cebf09f4-14f7-4def-8920-a2bab4abeed8" class="wlWriterSmartContent"&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; DataContractWithAnnotationsSerializerOperationBehavior : &lt;br /&gt;    DataContractSerializerOperationBehavior, IWsdlExportExtension&lt;br /&gt;{&lt;br /&gt;        ...&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)&lt;br /&gt;        {&lt;br /&gt;            InitXsdDataContractExporter(exporter);&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(IWsdlExportExtension).InvokeMember(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;ExportContract&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;br /&gt;               BindingFlags.InvokeMethod, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, m_DataContractSerializerOperationBehavior, &lt;br /&gt;               &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[] {  exporter, context });&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)&lt;br /&gt;        {&lt;br /&gt;            InitXsdDataContractExporter(exporter);&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(IWsdlExportExtension).InvokeMember(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;ExportEndpoint&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, &lt;br /&gt;                BindingFlags.InvokeMethod, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, m_DataContractSerializerOperationBehavior, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&lt;br /&gt;                new&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[] {  exporter, context });&lt;br /&gt;        }&lt;br /&gt;        ...&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;And that's it. If we have this data contract &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E7:11cfee08-3035-4826-97e6-ec7a4586f570" class="wlWriterSmartContent"&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;    [DataContract]&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; GetAccountBalanceResponseMessage&lt;br /&gt;    {&lt;br /&gt;        [DataMember]&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; AccountNumber;&lt;br /&gt;        [DataMember]&lt;br /&gt;        [DataMemberAnnotation(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;This is the account balance&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)]&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;decimal&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Balance;&lt;br /&gt;    }&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;We get this schema in wsdl&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" contenteditable="false" id="57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:48939615-5dbe-47f5-b504-2b505c2c43bc" class="wlWriterSmartContent"&gt;
&lt;pre style="background-color: rgb(240, 240, 240);"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:complexType &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="GetAccountBalanceResponseMessage"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;  &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:sequence&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;   &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&lt;br /&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:element &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;minOccurs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="0"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="AccountNumber"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; nillable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="true"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="xs:string"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:element &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;minOccurs&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="0"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Balance"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="xs:decimal"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&lt;br /&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:annotation&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&lt;br /&gt;        &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:appinfo&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;   &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&lt;br /&gt;          &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Surrogate &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;i:type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="d1p1:string"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;br /&gt;xmlns&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://schemas.microsoft.com/2003/10/Serialization/"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;br /&gt;xmlns:d1p1&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://www.w3.org/2001/XMLSchema"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;  &lt;br /&gt;xmlns:i&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;This is the account balance&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;Surrogate&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;br /&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;      &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:appinfo&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;   &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&lt;br /&gt;       &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:annotation&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;   &lt;br /&gt;     &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:element&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;   &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;   &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:sequence&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xs:complexType&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Here is the VS.NET solution to &lt;a href="http://www.agilior.pt/blogs/bruno.camara/downloads/WcfXsdAnnotater.zip"&gt;download&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://agilior.pt/blogs/bruno.camara/aggbug/6.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>BFC</dc:creator>
            <guid>http://agilior.pt/blogs/bruno.camara/archive/2006/10/01/6.aspx</guid>
            <pubDate>Sun, 01 Oct 2006 20:21:47 GMT</pubDate>
            <wfw:comment>http://agilior.pt/blogs/bruno.camara/comments/6.aspx</wfw:comment>
            <comments>http://agilior.pt/blogs/bruno.camara/archive/2006/10/01/6.aspx#feedback</comments>
            <slash:comments>325</slash:comments>
            <wfw:commentRss>http://agilior.pt/blogs/bruno.camara/comments/commentRss/6.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>