WCF SOAP到WCF在MVC中进行REST转换,给出了终点错误 [英] WCF SOAP to WCF REST conversion in MVC giving end point error

查看:57
本文介绍了WCF SOAP到WCF在MVC中进行REST转换,给出了终点错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< configuration>

< configsections>





< appsettings>

< add key =aspnet:UseTaskFriendlySynchronizationContextvalue =true>



< system。 web>

< compilation debug =true>

问题陈述:



使用WCF Service执行MVC CRUD操作。所有东西都可以正常使用SOAP,但是当我从SOAP更改为REST时,它会给出端点错误。我怀疑我的webconfig可能存在一些问题.. !!!



异常详情:



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

"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服务是托管正常,它正在运行。我在控制器中的WCF REST服务方法调用中得到上述异常,如:






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 :

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





我做错了什么?



我在解决方案中有两个项目



1. WCF服务库

2. MVC Razor应用程序



WCF服务库



IService1.cs



数据合同:





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:

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

        }







服务合同:






Service Contract:

[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






Service.cs

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:





App.config:

</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申请:




控制器:



插入操作:







MVC Application:


Controller:

Insert Operation:

[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:


[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:

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:










Web.Config:


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

推荐答案

这篇关于WCF SOAP到WCF在MVC中进行REST转换,给出了终点错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆