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应该自己生成端点,只要我没有尝试在其中添加身份验证,它就会这样做。
我的服务应用程序命名空间是' 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 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客户端enpoints:
<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>
答案 0 :(得分:1)
默认情况下,WCF将basicHttpBinding
用于http
以上的端点。看起来您正在尝试使用wsHttpBinding
,但没有为其定义端点,WCF也不知道使用wsHttpBinding
作为http
上任何通信的默认端点。
有两种方法可以解决这个问题。首先,您可以告诉WCF使用wsHttpBinding
进行服务配置文件的http
部分<protocolMaping>
上的任何通信,如下所示:
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
<add binding="wsHttpBinding" scheme="http" />
</protocolMapping>
请注意,这会有效地禁用basicHttpBinding
端点,因为您已告知WCF将wsHttpBinding
用于未明确设置为其他http
绑定的任何http
端点。您还将获得wsHttpBinding
的默认值,因为没有定义使用您指定的绑定配置的端点。
第二种方法是在wsHttpBinding
部分中使用<system.serviceModel>
的服务配置中明确定义端点,如下所示:
<services>
<service name="Congregatio.ServiceApp">
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="AuthenticationBinding"
contract="CongregatioServiceReference.ICongregatioService" />
</service>
</services>
请注意,name
属性需要与.svc文件的标记中的name属性匹配。
答案 1 :(得分:0)
我认为这是wcf中的一个错误。它为单个wcf写入2个端点。你应该删除多余的