WCF服务通信异常
我试图从我的mvc网站上访问WCF服务,这是我在服务库中创建的,但我一直遇到通信异常,这种方法应该只从数据库返回一行,因此我不认为这是内存问题,我设法使用这个服务来执行对数据库的插入,但是任何检索方法都失败了 我的代码可以在下面找到 用户服务WCF服务通信异常,wcf,model-view-controller,soap,service,Wcf,Model View Controller,Soap,Service,我试图从我的mvc网站上访问WCF服务,这是我在服务库中创建的,但我一直遇到通信异常,这种方法应该只从数据库返回一行,因此我不认为这是内存问题,我设法使用这个服务来执行对数据库的插入,但是任何检索方法都失败了 我的代码可以在下面找到 用户服务 IEnumerable<COUNTRY> IUserService.getCountries() { return new UsersRepository().getCountries(); } [OperationContract]
IEnumerable<COUNTRY> IUserService.getCountries()
{
return new UsersRepository().getCountries();
}
[OperationContract]
IEnumerable<COUNTRY> getCountries();
IUserService
IEnumerable<COUNTRY> IUserService.getCountries()
{
return new UsersRepository().getCountries();
}
[OperationContract]
IEnumerable<COUNTRY> getCountries();
服务Web配置
<?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" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<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>
</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>
<connectionStrings>
<add name="DSAEntities" connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;provider=System.Data.SqlClient;provider connection string="data source=HOODED;initial catalog=DSA;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<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>
</configuration>
网站网络配置
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IUserService" allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:50004/UserService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IUserService" contract="UserReference.IUserService"
name="BasicHttpBinding_IUserService" />
</client>
</system.serviceModel>
我的代码
public UserReference.UserServiceClient client = new UserReference.UserServiceClient();
IEnumerable<ROLE> roles = client.getRoles();
在数据上下文丢失之前强制枚举数据。 而不是
IEnumerable<COUNTRY> IUserService.getCountries()
{
return new UsersRepository().getCountries();
}
做
由于激活了includeExceptionDetailInFaults=true,服务器异常应该在那里的某个地方。你能发布更多的例外细节吗?在WCF中,一个CommunicationException可能有很多原因;但是你上面贴的代码是:IEnumerable getCountries;您确定使用的是正确的界面吗?