繁体   English   中英

找不到服务接口的WCF端点

[英]WCF Endpoint not found for service interface

关于stackoverflow有相似/相同的问题,但没有一个真正的帮助者。 我正在尝试通过WCF服务对WPF用户进行身份验证,但是当我调用IdentityValidator时,立即抛出此错误

"Could not find default endpoint element that references contract
'CongregatioServiceReference.ICongregatioService' 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."

就我所了解的WCF而言(我对此知之甚少),只要我没有尝试在其中添加身份验证,新的WCF便应自行生成端点,并且效果很好。

我的Service App命名空间是“ Congregatio.ServiceApp”,这是配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="owin:AutomaticAppStartup" value="false" />
  </appSettings>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
             <add name="xml" />
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
            <add name="xml" />
        </listeners>
      </source>
      <source name="myUserTraceSource" switchValue="Critical, Error, Warning">
        <listeners>
            <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
        <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Error.svclog" />
    </sharedListeners>
  </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="AuthenticationBinding">
          <security mode="Message">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>

        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="authBehavior">
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom"
                                    customUserNamePasswordValidatorType="Congregatio.ServiceApp.IdentityValidator,Congregatio.ServiceApp" />
          </serviceCredentials>
          <serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="Congregatio.ServiceApp.RoleValidator,Congregatio.ServiceApp">
          </serviceAuthorization>

        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <!-- Some connection strings i won't be sharing :( -->
  </connectionStrings>
</configuration>

尝试按照其他类似问题中的说明更改端点,但是随后出现Content not support exception

Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:50767/Service1.svc.  The client and service bindings may be mismatched

WPF客户要求:

<client>
     <!--Default Working One-->
            <endpoint address="http://localhost:50767/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_ICongregatioService"
                contract="CongregatioServiceReference.ICongregatioService"
                name="BasicHttpBinding_ICongregatioService" />
     <!-- My messy one -->
          <endpoint
                name="AuthenticationBinding"
                address="http://localhost:50767/Service1.svc"
                binding="wsHttpBinding"
                contract="CongregatioServiceReference.ICongregatioService"
                 />
        </client>

默认情况下,WCF将使用basicHttpBinding作为基于http的终结点。 似乎您正在尝试使用wsHttpBinding ,但没有为其定义终结点,WCF也不知道将wsHttpBinding用作通过http进行的任何通信的默认设置。

有两种解决方法。 首先,您可以在服务配置文件的<protocolMaping>部分中告诉WCF使用wsHttpBinding进行http上的任何通信,如下所示:

<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
  <add binding="wsHttpBinding" scheme="http" />
</protocolMapping>

请注意,这将有效地禁用basicHttpBinding端点,因为您已告知WCF对未显式设置为另一个http绑定的任何http端点使用wsHttpBinding 您还将获得wsHttpBinding的默认值,因为没有定义使用您指定的绑定配置的端点。

第二种方法是在<system.serviceModel>部分中使用wsHttpBinding的服务配置中显式定义一个端点,如下所示:

<services>
  <service name="Congregatio.ServiceApp">
    <endpoint address="" binding="wsHttpBinding"
              bindingConfiguration="AuthenticationBinding"
              contract="CongregatioServiceReference.ICongregatioService" />
  </service>
</services>

请注意, name属性需要与.svc文件标记中的名称属性匹配。

我认为这是WCF中的错误。 它为单个wcf写2个端点。 您应该删除多余的一个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM