title: How to get rid of tempuri.org in WCF service created by SharePoint Service Factory
body: <p>I am exposing a WCF service on SharePoint 2010 using a Service Factory class and cannot completly get rid of the tempuri.org namespace in the generated WSDL. </p>
  
  <p>Here is what I do:</p>
  
  <p><strong>The svc file in the ISAPI folder</strong>   </p>
  
  <pre><code>&lt;%@ServiceHost
      Language="C#"
      Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
      Service="MyService, [...]"   
  %&gt;
  </code></pre>
  
  <p><strong>The service contract</strong></p>
  
  <pre><code>using System.ServiceModel;
  
      namespace MyService
      {
          [ServiceContract(Namespace="http://myname.com")]
          interface IMyService
          {
              [OperationContract]
              string GetSomeDefinition();
          }
      }
  </code></pre>
  
  <p><strong>The service implementation</strong></p>
  
  <pre><code>using System;
  using System.ServiceModel;
  using System.ServiceModel.Activation;
  using Microsoft.SharePoint.Client.Services;
  
      namespace MyService
      {
          [ServiceBehavior(Namespace = "http://myname.com")]
          [BasicHttpBindingServiceMetadataExchangeEndpointAttribute]
          [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
          class MyService : IMyService
          {
              public string GetSomeDefinition()
              {
                  // do some stuff...
                  return result;
              }
          }
      }
  </code></pre>
  
  <p><strong>The WSDL</strong></p>
  
  <pre><code>&lt;wsdl:definitions name="MyService" targetNamespace="http://myname.com" [...]&gt;
    &lt;wsdl:import namespace="http://tempuri.org/" location="http://localhost/_vti_bin/myservice.svc/mex?wsdl=wsdl0" /&gt; 
    [...]
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p>The problem now is that the WSDL is split up in two. One with the correct new namespace <a href="http://myname.com" rel="nofollow">http://myname.com</a> and one with the default namespace <a href="http://tempuri.org" rel="nofollow">http://tempuri.org</a>. Normally you get rid of it by using a bindingNamespace attribute on the endpoint configuration. But because I am using a Service Factory I cannot do so. Trying to define a service endpoint in web.config fails with the following error: A binding instance has already been associated to listen <a href="http://localhost/" rel="nofollow">http://localhost/</a>...</p>
  
  <p><strong>Web.config chunk</strong></p>
  
  <pre><code>  &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="MyService.MyService"&gt;
          &lt;endpoint address="http://localhost/_vti_bin/myservice.svc" binding="basicHttpBinding" contract="MyService.IMyService" bindingNamespace="http://myname.com" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>2010-10-07 Update:
  I have tried to derive the MultipleBaseAddressBasicHttpBindingServiceHostFactory and add the endpoint binding namespace when the ServiceHost is created. This does not succeed because the endpoint collection is empty at that point of time.</p>