添加WCF serivce引用,或为我自己的WCF服务使用svcutil.exe

添加WCF serivce引用,或为我自己的WCF服务使用svcutil.exe,wcf,wcf-binding,wcf-security,wcf-client,Wcf,Wcf Binding,Wcf Security,Wcf Client,添加我开发的WCF服务时遇到问题。WCF配置为使用证书。这是可行的,但由于某些原因,现在不行了。以下是我的想法 场景1: 在Web浏览器上浏览时,它不会显示xml,而是显示: 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 fro

添加我开发的WCF服务时遇到问题。WCF配置为使用证书。这是可行的,但由于某些原因,现在不行了。以下是我的想法

场景1:

在Web浏览器上浏览时,它不会显示xml,而是显示:

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 

.....
.....
场景2:

在下面运行svcutil.exe时:

svcutil.exe

它产生:

 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'.

    <?xml version="1.0" encoding="utf-16"?><Fault xmlns="http://www.w3.org/2003/05/soap-envelope"><Code><Value>Sender</Value><Subcode><Value xmlns:a="http://doc
s.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:InvalidSecurity</Value></Subcode></Code><Reason><Text xml:lang="en-GB">An error occur
red when verifying security for the message.</Text></Reason></Fault>


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').'.
正在尝试从下载元数据'https://depart.Mydomain.com/Ver.svc?wsdl'使用WS-Metadata Exchange或DISCO。
Microsoft(R)服务模型元数据工具
[微软(R)Windows(R)通信基础,版本4.0.30319.1]
版权所有(c)微软公司。版权所有。
错误:无法从中获取元数据https://depart.Mydomain.com/Ver.svc?wsdl
如果这是您可以访问的Windows(R)通信基础服务,请检查您是否已在指定ADDR启用元数据发布。
字母S。有关启用元数据发布的帮助,请参阅位于的MSDN文档http://go.microsoft.com/fwlink/?LinkId=65455.
WS元数据交换错误
URI:https://depart.Mydomain.com/Ver.svc?wsdl
元数据包含无法解析的引用:'https://depart.Mydomain.com/Ver.svc?wsdl'.
Sendera:InvalidSecurity发生错误
验证消息的安全性时为红色。
HTTP获取错误
URI:https://depart.Mydomain.com/Ver.svc?wsdl
url上的文档https://depart.Mydomain.com/Ver.svc?wsdl 未被识别为已知文档类型。
来自每种已知类型的错误消息可能有助于解决问题:
-来自“XML架构”的报告是“无法识别文档格式(内容类型为“text/html;charset=UTF-8”)。
-“DISCO文档”中的报告为“下载时出错”https://depart.Mydomain.com/Ver.svc?disco'.'.
-请求失败,HTTP状态为403:禁止。
-报告来自'https://depart.Mydomain.com/Ver.svc?wsdl“是”文档格式无法识别(内容类型为“text/html;ch
arset=UTF-8’”。
-来自“WSDL文档”的报告是“文档格式无法识别(内容类型为“text/html;charset=UTF-8”)。
场景3:

当我尝试在VisualStudio2010中添加服务引用时,它在场景2中生成了类似的错误

下面是web.config:

   <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMalformedMessages="true"
        logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" />
    </diagnostics>
    <services>
      <service behaviorConfiguration="VServiceBehaviour"
               name="Ver.Service">
        <endpoint address="ver" listenUri="" binding="wsHttpBinding" bindingConfiguration="wshttpbindingcfg"
                   contract="Ver.IVer" bindingNamespace="http://www.MyDomain.com/ver" behaviorConfiguration ="VerEndpointBehaviour">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="mexhttpbinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://depart.MyDomain.com/" />
          </baseAddresses>
        </host>
      </service>    
    </services>
    <bindings>
      <mexHttpBinding>
        <binding name="mexhttpbinding" />
      </mexHttpBinding>
      <wsHttpBinding>

        <binding name="wshttpbindingcfg" maxReceivedMessageSize="2000000000" sendTimeout="00:10:00">
          <readerQuotas maxStringContentLength="2000000000"/>

          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="Certificate" establishSecurityContext="False" negotiateServiceCredential="False" algorithmSuite="Default"/>
          </security>

        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="VerEndpointBehaviour">
          <instanceContextBehavior/>
          <verInspectorBehavior/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="VServiceBehaviour">
          <dataContractSerializer maxItemsInObjectGraph="100000000"/>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />

          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="PeerOrChainTrust" trustedStoreLocation="LocalMachine" mapClientCertificateToWindowsAccount="false"/>
            </clientCertificate>

            <serviceCertificate
               x509FindType="FindByThumbprint"
               findValue="xxx"
               storeLocation="LocalMachine"
               storeName="My"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>


感谢您提前提出的建议

对于安全通信信道,请使用MEXHTTPS绑定(带附加s)而不是mexHttpBinding,请参阅:并更换

<serviceMetadata httpGetEnabled="true" /> 


还有附加的s

<serviceMetadata httpsGetEnabled="true" />