Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<configuration>
<configsections>


<appsettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true">

<system.web>
<compilation debug="true">
Problem Statement:

Performing MVC CRUD operations using WCF Service.Everything was working fine with SOAP,but when i changed from SOAP to REST it is giving end point error.I suspect that there might be some problem with my webconfig..!!!

Exception Details:

SQL
"There was no endpoint listening at http://localhost:8733/Design_Time_Addresses/ALCMS.MasterConfigurationService/Service1/InsertAssetType that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."



WCF REST service is hosting properly and it is running.I'm getting the exception mentioned above in WCF REST Service method calls in controller like :

C#
objSvcMasterConfig.InsertAssetType(objAssetTypeDC);
   objSvcMasterConfig.UpdateAssetType(objAssetTypeDC);
   objSvcMasterConfig.DeleteAssetType(objAssetTypeDC);


What i'm doing wrong??

I'm having two projects in Solution

1. WCF Service library
2. MVC Razor application

WCF Service Library

IService1.cs

Data Contract:

C#
[DataContract]
        public class AssetTypeDC
        {
            [DataMember]
            public int ID { get; set; }
            [DataMember]
            public int AssetTypeID { get; set; }
            [DataMember]
            public string Name { get; set; }

        }



Service Contract:

C#
[ServiceContract]
        public interface IService1
        {
            #region Asset Type
            [OperationContract]
            [WebInvoke(Method = "POST",
                     RequestFormat = WebMessageFormat.Json,
                     ResponseFormat = WebMessageFormat.Json,
                     UriTemplate = "InsertAssetType")]
            bool InsertAssetType(AssetTypeDC objAssetTypeDC);

            [WebInvoke(Method = "PUT",
                     RequestFormat = WebMessageFormat.Json,
                     ResponseFormat = WebMessageFormat.Json,
                     UriTemplate = "UpdateAssetType")]
            [OperationContract]
            bool UpdateAssetType(AssetTypeDC objAssetTypeDC);

            [WebInvoke(Method = "DELETE",
                     RequestFormat = WebMessageFormat.Json,
                     ResponseFormat = WebMessageFormat.Json,
                     UriTemplate = "DeleteAssetType")]
            [OperationContract]
            bool DeleteAssetType(AssetTypeDC objAssetTypeDC);

            #endregion


        }



Service.cs

C#
public bool InsertAssetType(AssetTypeDC objAssetTypeDC)
{
    try
    {
        objAssetType.ID = objAssetTypeDC.ID;
        objAssetType.AssetTypeID = objAssetTypeDC.AssetTypeID;
        objAssetType.Name = objAssetTypeDC.Name;
        dbEntity.AssetTypes.Attach(objAssetType);
        var entry = dbEntity.Entry(objAssetType);
        dbEntity.AssetTypes.Add(objAssetType);
        dbEntity.SaveChanges();
        return true;
    }
    catch
    {
        return false;
    }
}

public bool UpdateAssetType(AssetTypeDC objAssetTypeDC)
{
    try
    {
        objAssetTypeID = ID;
        objAssetType.AssetTypeID = objAssetTypeDC.AssetTypeID;
        objAssetType.Name = objAssetTypeDC.Name;
        dbEntity.AssetTypes.Attach(objAssetType);
        var entry = dbEntity.Entry(objAssetType);
        entry.Property(e => e.Name).IsModified = true;
        dbEntity.SaveChanges();
        return true;
    }
    catch
    {
        return false;
    }
}

public bool DeleteAssetType(AssetTypeDC objAssetTypeDC)
{
    try
    {
        objAssetType.AssetTypeID = objAssetTypeDC.AssetTypeID;
        objAssetType.ID = objAssetTypeDC.ID;
        dbEntity.AssetTypes.Attach(objAssetType);
        dbEntity.Entry(objAssetType).State = EntityState.Deleted;
        dbEntity.SaveChanges();
        return true;
    }
    catch
    {
        return false;
    }
}


App.config:

XML
</system.web>
  <system.serviceModel>
    <services>
      <service name="ALCMS.MasterConfigurationService.Service1" behaviorConfiguration="ALCMS.MasterConfigurationService.Service1Behaviour">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/ALCMS.MasterConfigurationService/Service1/" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="webHttpBinding" contract="ALCMS.MasterConfigurationService.IService1" behaviorConfiguration="ALCMS.MasterConfigurationService.RESTEndpointBehaviour">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ALCMS.MasterConfigurationService.RESTEndpointBehaviour">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ALCMS.MasterConfigurationService.Service1Behaviour">
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
<connectionStrings><add name="DB_V2Entities" connectionString="metadata=res://*/Entities.MasterConfigurationEntity.csdl|res://*/Entities.MasterConfigurationEntity.ssdl|res://*/Entities.MasterConfigurationEntity.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SQL-PC\SQLEXPRESS;initial catalog=DB_V2;user id=sa;password=Sql@123;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings></configuration>




MVC Application:


Controller:

Insert Operation:

SQL
[HttpPost]
      public ActionResult Create(AssetTypeModel assettypemodel)
      {
           if (ModelState.IsValid)
          {
              objAssetTypeDC.ID = 1;
              objAssetTypeDC.AssetTypeID = assettypemodel.ID;
              objAssetTypeDC.Name = assettypemodel.Name;
              objSvcMasterConfig.InsertAssetType(objAssetTypeDC);
              return RedirectToAction("Index");
          }

          return View(assettypemodel);
      }



Update Operation:


SQL
[HttpPost]
   public ActionResult Edit(AssetTypeModel assettypemodel, int id, int ID)
   {
       if (ModelState.IsValid)
       {
           objAssetTypeDC.ID = assettypemodel.ID = ID;
           objAssetTypeDC.AssetTypeID = assettypemodel.AssetTypeID = id;
           objAssetTypeDC.Name = assettypemodel.Name;
           objSvcMasterConfig.UpdateAssetType(objAssetTypeDC);
           return RedirectToAction("Index");
       }
       return View(assettypemodel);
   }



Delete Operation:

SQL
public ActionResult Delete(int id = 0, int ID = 0)
    {
        AssetTypeModel assettypemodel = db.AssetType.Find(id, ID);
        if (assettypemodel == null)
        {

            return HttpNotFound();
        }
        return View(assettypemodel);
    }





Web.Config:


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

   <configuration>
     <configSections>
       <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
     </configSections>
     <connectionStrings>
       <add name="DB" connectionString="Data Source=SQL-PC\SQLEXPRESS;initial catalog=DB_V2;Persist Security Info=True;User ID=sa;Password=Sql@123;Pooling=False;" providerName="System.Data.SqlClient" />

       <add name="DBEntities" connectionString="metadata=res://*/Entities.WebEntity.csdl|res://*/Entities.WebEntity.ssdl|res://*/Entities.WebEntity.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SQL\SQLEXPRESS;initial catalog=DB_V2;user id=sa;Password=Sql@123;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
     <appSettings>
       <add key="webpages:Version" value="2.0.0.0" />
       <add key="webpages:Enabled" value="false" />
       <add key="PreserveLoginUrl" value="true" />
       <add key="ClientValidationEnabled" value="true" />
       <add key="UnobtrusiveJavaScriptEnabled" value="true" />
     </appSettings>
     <system.web>
       <compilation debug="true" targetFramework="4.5"><assemblies><add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /></assemblies></compilation>
       <httpRuntime targetFramework="4.5" />
       <authentication mode="Forms">
         <forms loginUrl="~/Login" protection="All" timeout="2880" />
       </authentication>
        <sessionState mode="InProc" timeout="30" stateConnectionString="tcpip=SQL-PC\SQLEXPRESS,1433" cookieless="false" regenerateExpiredSessionId="false" />
       <pages>
         <namespaces>
           <add namespace="System.Web.Helpers" />
           <add namespace="System.Web.Mvc" />
           <add namespace="System.Web.Mvc.Ajax" />
           <add namespace="System.Web.Mvc.Html" />
           <add namespace="System.Web.Optimization" />
           <add namespace="System.Web.Routing" />
           <add namespace="System.Web.WebPages" />
         </namespaces>
       </pages>
     </system.web>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
       <validation validateIntegratedModeConfiguration="false" />
       <handlers>
         <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
         <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
         <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
         <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
         <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
         <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
       </handlers>
     </system.webServer>
     <runtime>
       <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
           <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
           <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
         </dependentAssembly>
         <dependentAssembly>
           <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
           <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
         </dependentAssembly>
         <dependentAssembly>
           <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
           <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
         </dependentAssembly>
       </assemblyBinding>
     </runtime>
     <entityFramework>
       <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
     </entityFramework>
    <system.serviceModel>
       <bindings>
         <webHttpBinding>
           <binding name="WebHttpBinding_IService1" />
         </webHttpBinding>
       </bindings>
      <behaviors>
        <endpointBehaviors>
          <behavior name="ALCMS.MasterConfigurationService.RESTEndpointBehaviour">
            <webHttp />
          </behavior>
        </endpointBehaviors>
      </behaviors>
       <client>
        <endpoint address="http://localhost:8733/Design_Time_Addresses/ALCMS.MasterConfigurationService/Service1/" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_IService1" behaviorConfiguration="ALCMS.MasterConfigurationService.RESTEndpointBehaviour" contract="MasterConfigurationServiceReference.IService1" name="WebHttpBinding_IService1" />
       </client>
     </system.serviceModel>
   </configuration>
Posted
Updated 8-Jun-14 22:22pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900