【问题标题】:Endpoint could not be found exception - WCF Web Service找不到端点异常 - WCF Web 服务
【发布时间】:2012-05-07 15:48:11
【问题描述】:

我无法让 Duplex Web 服务正常工作,我收到此错误:

找不到引用合约的默认端点元素 ServiceModel 客户端配置部分中的“IService1”。这 可能是因为没有为您的应用程序找到配置文件, 或者因为找不到与此合同匹配的端点元素 在客户端元素中。

这是我的单元测试尝试访问服务时抛出的。我发现了类似的 SO 问题:

Could not find default endpoint element

WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'

答案是“将配置文件包含到另一个项目中”,但这究竟是什么意思?

  • 我是否将服务编译成 DLL 并包含在内?
  • 我是复制“system.serviceModel”中包含的所有内容还是其中的一部分?
  • 与端点有关?

编辑:配置文件

Web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
      <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name ="svcbh">
          <serviceMetadata httpGetEnabled="False"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->
    <services>
      <service name ="Test_Duplex.Service1" behaviorConfiguration ="svcbh" >
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:3857/Service1.svc" />
          </baseAddresses>
        </host>
        <endpoint name ="duplexendpoint"
                  address =""
                  binding ="wsDualHttpBinding"
                  contract ="Test_Duplex.IService1"/>
        <endpoint name ="MetaDataTcpEndpoint"
                  address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

输出配置

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
                <binding name="duplexendpoint" closeTimeout="00:01:00"      openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                    transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8"   useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00" />
                    <security mode="Message">
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsDualHttpBinding>
        </bindings>
        <client>
             <endpoint address="http://localhost:3857/Service1.svc" binding="wsDualHttpBinding"
                bindingConfiguration="duplexendpoint" contract="Test_Duplex.IService1"
                name="duplexendpoint">
                <identity>
                    <userPrincipalName value="12680@altus.local" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

【问题讨论】:

  • 你能发布你的客户端配置文件吗?
  • 添加了我的配置文件。即使添加“Test_Duplex”(我的命名空间),错误也是一样的。
  • 您的托管环境是什么?您还可以删除主机部分中的基地址并查看它是否有效。如果托管在 IIS 上,则主机基地址将被忽略,地址由 IIS 分配
  • 我删除了 部分中的所有内容,但仍然找不到端点。我不确定我的托管环境是什么,我在 Visual Studio C#、winXP 上运行它,初始化时它说 ASP.NET Development Server 具有相同的地址,无论我是否声明了

标签: c# wcf web-services soap


【解决方案1】:

我将 wsdl 生成的文件(Service1.svc、output.config)改为 服务引用,并从那里获取了我的类定义。你也可以看到tutorials 这样做。

因为我的老板教我用命令提示符做这件事,所以它一定是从我头上滑过。

这修复了“找不到端点”错误。

【讨论】:

  • 请注意,Web 引用包装到 wsdl.exe 并将使用限制为 basicHttpBinding 或派生类;这是因为它为 .NET 1.x 和 2.x 客户端创建代理。添加服务引用会覆盖 svcutil.exe,为 3.x+ 的客户端创建代理,因此从某种意义上说,您拥有更大的灵活性。有关详细信息,请参阅 stackoverflow.com/questions/308454/…andrewtokeley.net/archive/2008/07/10/…
【解决方案2】:

这是配置文件的问题。 当它生成配置文件时,它并没有完全指定类型的命名空间。 通常,您只需要&lt;Namespace&gt;.IService1

【讨论】:

  • 抱歉,这不起作用。我尝试了所有可用的命名空间。
猜你喜欢
  • 1970-01-01
  • 2015-11-02
  • 2023-04-01
  • 1970-01-01
  • 2019-12-10
  • 1970-01-01
  • 2013-06-29
  • 2012-06-30
相关资源
最近更新 更多