wcf wcf-binding

WCF http vinculante



binding wcf web config (1)

Creo una aplicación de servicio wcf y un proyecto asp.net mvc (como cliente). Agregué mi servicio wcf mediante el archivo Agregar referencia de servicio a mi referencia asp.net mvc. Utilizo Entity Framework para conectar DB en mi aplicación wcf. Tengo un servicio UserManagement.svc.cs . Este es mi código UserManagement.svc.cs :

public class UserManagement : IUserManagement { iFlowEntities db = new iFlowEntities(); public void AddRole(role role) { db.roles.Add(role); db.SaveChanges(); } public List<role> RoleList() { List<role> roles; roles = db.roles.ToList(); return roles; } }

Y uso este servicio en mi UserController en la acción RoleList () en asp.net mvc y este es el código de acción:

public ActionResult RoleList() { IList<UserManagement.role> roles = new List<UserManagement.role>(); roles = UserClient.RoleList(); return View("_RoleList",roles); }

y la variable UserClient definen en el cuerpo del controlador como: UserManagement.UserManagementClient UserClient = new UserManagement.UserManagementClient();

Cuando ejecuto el proyecto asp.net me sale este error:

Se produjo un error al recibir la respuesta HTTP a http: // localhost: 1730 / UserManagement.svc . Esto podría deberse a que el enlace del punto final del servicio no utiliza el protocolo HTTP. Esto también podría deberse a que el servidor ha cancelado un contexto de solicitud HTTP (posiblemente debido a que el servicio se ha apagado).

Busqué en Google y veo respuestas múltiples y las pruebo, pero no tengo resultados para mí y esta respuesta como esta y esto y esto .

Y este es mi archivo de configuración del servicio wcf:

<?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 maxRequestLength ="262144" executionTimeout="103600" 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" /> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> <!-- 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="false" /> </behavior> </serviceBehaviors> </behaviors> <protocolMapping> <add binding="wsHttpBinding" 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="iFlowEntities" connectionString="metadata=res://*/Model.DBContext.csdl|res://*/Model.DBContext.ssdl|res://*/Model.DBContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=iFlow;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework> </configuration>

Editado:

Sí, agrego DataContract y DataMember a mi clase y ServiceContract y OperationContract .

Este es el archivo de configuración de mi cliente:

<?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=301880 --> <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="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> </system.web> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> </dependentAssembly> </assemblyBinding> </runtime> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IUserManagement" /> <binding name="BasicHttpBinding_IDepartmentManagement" /> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost:1730/UserManagement.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserManagement" contract="UserManagement.IUserManagement" name="BasicHttpBinding_IUserManagement" /> <endpoint address="http://localhost:1730/DepartmentManagement.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDepartmentManagement" contract="DepartmentManagement.IDepartmentManagement" name="BasicHttpBinding_IDepartmentManagement" /> </client> </system.serviceModel> </configuration>


De acuerdo con mi experiencia, ¡creo que este tema es un asunto de Entity Framework ! Cada vez que devuelve Entidades en WCF Service, intenta devolver entidades con sus relaciones, mientras que WCF no puede serializarlas para el cliente. Para resolver este problema, simplemente desactive la opción de Proxy Creation en el constructor de DbContext:

public class iFlowEntities : DbContext { public iFlowEntities() { Configuration.ProxyCreationEnabled = false; } }