title: Adding WCF serivce reference, or using svcutil.exe for my own WCF service
body: <p>I have a problem adding a WCF service that I developed. The WCF is configured to use certificate. It was working, but not now for some reasons. Below is what I have triedL</p>
  
  <p><strong>Scenario 1:</strong></p>
  
  <p>When browsing <a href="https://depart.MyDomain.com/ver.svc?wsdl" rel="nofollow">https://depart.MyDomain.com/ver.svc?wsdl</a> on Web browser, it does <strong>NOT</strong> show the xml, but show:</p>
  
  <pre><code>You have created a service.
  
  To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:
  
  svcutil.exe http://depart.MyDomain.com/ver.svc?wsdl 
  
  .....
  .....
  </code></pre>
  
  <p><strong>Scenario 2:</strong></p>
  
  <p>When run svcutil.exe below:</p>
  
  <p>svcutil.exe <a href="https://depart.MyDomain.com/ver.svc?wsdl" rel="nofollow">https://depart.MyDomain.com/ver.svc?wsdl</a></p>
  
  <p>It generates:</p>
  
  <pre><code> Attempting to download metadata from 'https://depart.Mydomain.com/Ver.svc?wsdl' using WS-Metadata Exchange or DISCO.
  Microsoft (R) Service Model Metadata Tool
  [Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
  Copyright (c) Microsoft Corporation.  All rights reserved.
  
  Error: Cannot obtain Metadata from https://depart.Mydomain.com/Ver.svc?wsdl
  
  If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified addr
  ess.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.
  
  
  WS-Metadata Exchange Error
      URI: https://depart.Mydomain.com/Ver.svc?wsdl
  
      Metadata contains a reference that cannot be resolved: 'https://depart.Mydomain.com/Ver.svc?wsdl'.
  
      &lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Fault xmlns="http://www.w3.org/2003/05/soap-envelope"&gt;&lt;Code&gt;&lt;Value&gt;Sender&lt;/Value&gt;&lt;Subcode&gt;&lt;Value xmlns:a="http://doc
  s.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;a:InvalidSecurity&lt;/Value&gt;&lt;/Subcode&gt;&lt;/Code&gt;&lt;Reason&gt;&lt;Text xml:lang="en-GB"&gt;An error occur
  red when verifying security for the message.&lt;/Text&gt;&lt;/Reason&gt;&lt;/Fault&gt;
  
  
  HTTP GET Error
      URI: https://depart.Mydomain.com/Ver.svc?wsdl
  
      The document at the url https://depart.Mydomain.com/Ver.svc?wsdl was not recognized as a known document type.
  The error message from each known type may help you fix the problem:
  - Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
  - Report from 'DISCO Document' is 'There was an error downloading 'https://depart.Mydomain.com/Ver.svc?disco'.'.
    - The request failed with HTTP status 403: Forbidden.
  - Report from 'https://depart.Mydomain.com/Ver.svc?wsdl' is 'The document format is not recognized (the content type is 'text/html; ch
  arset=UTF-8').'.
  - Report from 'WSDL Document' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
  </code></pre>
  
  <p><strong>Scenario 3:</strong></p>
  
  <p>When I tried add service reference in Visual studio 2010, it generates similar error in scenario 2</p>
  
  <p>Below is web.config:</p>
  
  <pre><code>   &lt;system.serviceModel&gt;
      &lt;diagnostics&gt;
        &lt;messageLogging logEntireMessage="true" logMalformedMessages="true"
          logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" /&gt;
      &lt;/diagnostics&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="VServiceBehaviour"
                 name="Ver.Service"&gt;
          &lt;endpoint address="ver" listenUri="" binding="wsHttpBinding" bindingConfiguration="wshttpbindingcfg"
                     contract="Ver.IVer" bindingNamespace="http://www.MyDomain.com/ver" behaviorConfiguration ="VerEndpointBehaviour"&gt;
            &lt;identity&gt;
              &lt;dns value="localhost" /&gt;
            &lt;/identity&gt;
          &lt;/endpoint&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="mexhttpbinding" contract="IMetadataExchange" /&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://depart.MyDomain.com/" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;    
      &lt;/services&gt;
      &lt;bindings&gt;
        &lt;mexHttpBinding&gt;
          &lt;binding name="mexhttpbinding" /&gt;
        &lt;/mexHttpBinding&gt;
        &lt;wsHttpBinding&gt;
  
          &lt;binding name="wshttpbindingcfg" maxReceivedMessageSize="2000000000" sendTimeout="00:10:00"&gt;
            &lt;readerQuotas maxStringContentLength="2000000000"/&gt;
  
            &lt;security mode="TransportWithMessageCredential"&gt;
              &lt;message clientCredentialType="Certificate" establishSecurityContext="False" negotiateServiceCredential="False" algorithmSuite="Default"/&gt;
            &lt;/security&gt;
  
          &lt;/binding&gt;
        &lt;/wsHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;behaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="VerEndpointBehaviour"&gt;
            &lt;instanceContextBehavior/&gt;
            &lt;verInspectorBehavior/&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="VServiceBehaviour"&gt;
            &lt;dataContractSerializer maxItemsInObjectGraph="100000000"/&gt;
            &lt;serviceMetadata httpGetEnabled="true" /&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
  
            &lt;serviceCredentials&gt;
              &lt;clientCertificate&gt;
                &lt;authentication certificateValidationMode="PeerOrChainTrust" trustedStoreLocation="LocalMachine" mapClientCertificateToWindowsAccount="false"/&gt;
              &lt;/clientCertificate&gt;
  
              &lt;serviceCertificate
                 x509FindType="FindByThumbprint"
                 findValue="xxx"
                 storeLocation="LocalMachine"
                 storeName="My"/&gt;
            &lt;/serviceCredentials&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Thanks for any advice in advance!</p>