0

我正在使用 Visual Studio 2012 通过“添加服务引用”将 WCF 客户端添加到类项目中。但是我收到了众所周知的错误:

Could not find default endpoint element that references contract ‘Service1.IService1′ in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

我遵循的步骤是:(1)通过 svcutil.exe 创建 Service1.cs 和 output.config,(2)添加服务引用我将引用命名空间作为“MyFirstWcfWebServiceReference”。(3) 将您现有的 Service1.cs 文件添加到项目中。(4) 在 app.config 中删除了“MyFirstWcfWebServiceReference”并在合同中只保留 IService1,(6) 构建项目。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="WCFServiceBinding" />
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost/webiste/WebService.svc"
            binding="basicHttpBinding" bindingConfiguration="WCFServiceBinding"
            contract="IService1" name="WCFServiceBinding" />
        </client>
      </system.serviceModel>
</configuration>
4

0 回答 0