WCF http binding

Ich erstelle eine wcf-Dienstanwendung und ein asp.net-MVC-Projekt (als Client). Ich habe meinen wcf-Dienst über die Datei "Dienstreferenz hinzufügen" zu meiner asp.net-MVC-Referenz hinzugefügt. Ich verwende Entity Framework, um die Datenbank in meiner wcf-Anwendung zu verbinden. Ich habe einUserManagement.svc.cs Bedienung. Das ist meinUserManagement.svc.cs codes:

 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;
    }

}

Und ich benutze diesen Dienst in meinemUserController in RoleList () Aktion in asp.net mvc und dies ist der Aktionscode:

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

und UserClient-Variable definieren im Controller-Body wie:UserManagement.UserManagementClient UserClient = new UserManagement.UserManagementClient();

Wenn ich das asp.net-Projekt starte, erhalte ich folgende Fehlermeldung:

Beim Empfang der HTTP-Antwort auf @ ist ein Fehler aufgetretehttp: // localhost: 1730 / UserManagement.svc. Dies kann daran liegen, dass die Bindung des Service-Endpunkts nicht das HTTP-Protokoll verwendet. Dies kann auch daran liegen, dass ein HTTP-Anforderungskontext vom Server abgebrochen wird (möglicherweise aufgrund des Herunterfahrens des Dienstes).

Ich habe gegoogelt und sehe mehrere Antworten und teste sie, habe aber kein Ergebnis für mich und diese Antwort wieDie undDie undDie.

Und das ist meine wcf-Dienstkonfigurationsdatei:

<?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>

Bearbeitet:

Ja, ich füge @ hinDataContract undDataMember zu meiner Klasse undServiceContract undOperationContract.

Dies ist meine Client-Konfigurationsdatei:

<?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>

Antworten auf die Frage(2)

Ihre Antwort auf die Frage