【问题标题】:Add service reference failed添加服务引用失败
【发布时间】:2011-11-16 08:11:57
【问题描述】:

我使用 iis 7.0 托管我的 wcf,网址是:

https://example.com/CustPortal/CustomerService.svc

当我在 vs2008 中添加服务引用时,出现以下错误:

The document at the url https://example.com/CustPortal/CustomerService.svc was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'DISCO Document' is 'There was an error downloading 'https://el-cust-port01/CustPortal/CustomerService.svc?disco'.'.
  - Unable to connect to the remote server
  - No connection could be made because the target machine actively refused it 59.37.71.86:443
- Report from 'WSDL Document' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'https://193.91.152.191/CustPortal/CustomerService.svc' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
Metadata contains a reference that cannot be resolved: 'https://193.91.152.191/CustPortal/CustomerService.svc'.
Metadata contains a reference that cannot be resolved: 'https://193.91.152.191/CustPortal/CustomerService.svc'.
If the service is defined in the current solution, try building the solution and adding the service reference again.

我的 web.config 是

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataBehavior">
          <serviceMetadata httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceCredentials>
            <serviceCertificate storeName="My"  x509FindType="FindBySubjectName" findValue="TESTCERT" storeLocation="LocalMachine"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="metadataBehavior" name="EV.Services.CustomerService">
        <endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfig" contract="EV.Contracts.ICustomer" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBindingConfig">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>

【问题讨论】:

    标签: .net wcf visual-studio service-reference


    【解决方案1】:

    我认为您还缺少 Metadata Excahnge (mex) 端点。尝试添加:

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    

    在您现有的端点下方。您应该能够打开网络浏览器:

    https://193.91.152.191/CustPortal/CustomerService.svc?wsdl

    并查看实际显示的 WSDL 文件。

    【讨论】:

    • 嗨,你是超人,它适用于我使用你的代码。但是当我调用该方法时遇到了另一个问题:无法为具有权限“193.91.152.191”的 SSL/TLS 安全通道建立信任关系。
    • 我搜索它并使用以下代码得到了解决方案:ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnValidationCallback);public static bool OnValidationCallback(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors) { return true; }
    • 您可以在此处找到使 wcf 服务通过 https 工作所需的所有更改的列表。看起来那是你唯一缺少的一个。 codeproject.com/Articles/36705/…
    【解决方案2】:

    你是在家里主持吗?该错误基本上表明您无法访问IP地址,而我可以。那可能是不支持“nat loopback”的路由器,因此您无法从网络内部访问您的外部 IP 地址。尝试按其本地 IP 地址添加引用。

    【讨论】:

    【解决方案3】:

    在你本地电脑的hosts文件(C:\Windows\System32\drivers\etc\hosts)中添加服务器的主机名和webservice的IP地址

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多