【发布时间】:2015-08-25 07:55:28
【问题描述】:
我的复杂类型有一个单独的层DataAccessLayer(DAL),还有一个单独的业务层BusinessLogicLayer(BL)。
我以ServiceLayer(SL) 创建了一个 wcf 服务应用程序项目,并添加了使用 BL 方法和 DAL 复杂类型作为返回值的服务。
现在,我在我的 mvc 项目中从 myService 添加引用时遇到了一个问题,那就是:
添加我对 myService 的引用后,在 Refrence.cs 中为使用它的每个 myComplex 类型生成自己的复杂类型。
我不想自己生成复杂类型并在 DAL 使用我的复杂类型。
DAL
using System.Runtime.Serialization;
namespace DAL
{
[DataContract]
public partial class MyComplexType
{
//...
[DataMember]
//my prop
//...
}
}
BL
namespace BL
{
public partial class MyRepository
{
public List<DAL.MyComplexType> MyMethod(int param1,int param2)
{
var parameters= new List<SqlParameter>();
parameters.Add(new SqlParameter("Param1",SqlDbType.Int){ Value = param1 });
parameters.Add(new SqlParameter("Param2",SqlDbType.Int){ Value = param2 });
var result = DAL.RunProcedure("MyProc", parameters);
return result.ConvertToList<DAL.MyComplexType>();
}
}
}
止损
namespace SL
{
[ServiceContract]
public interface IMyService
{
[OperationContract]
List<DAL.MyComplexType> MyServiceMethod(int param1,int param2);
}
}
namespace SL
{
public class MyService : IMyService
{
public List<DAL.MyComplexType> MyServiceMethod(int param1, int param2)
{
BL.MyRepository bl = new BL.MyRepository();
List<DAL.MyComplexType> result = bl.MyMethod(param1, param2);
return result;
}
}
}
Refrence.cs 类在 MyMvcProject 添加 MyService 引用服务后:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyMvcProject.MyService
{
using System.Data;
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "MyService.IMyService")]
public interface IMyService
{
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IMyService/MyServiceMethod", ReplyAction = "http://tempuri.org/IMyService/MyServiceMethodResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
MyMvcProject.MyService.MyServiceMethodResponse MyServiceMethod(MyMvcProject.MyService.MyServiceMethodRequest request);
// CODEGEN: Generating message contract since the operation has multiple return values.
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMyService/MyServiceMethod", ReplyAction="http://tempuri.org/IMyService/MyServiceMethodResponse")]
System.Threading.Tasks.Task<MyMvcProject.MyService.MyServiceMethodResponse> MyServiceMethodAsync(MyMvcProject.MyService.MyServiceMethodRequest request);
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.datacontract.org/2004/07/DAL")]
public partial class MyComplexType : object {
//private props ...
//..
/// <remarks/>
//public props
}
//.... other bloks
}
使用的服务引用方法的返回类型是 MyMvcProject.MyService.MyComplexType
MyMvcProject.MyService.MyServiceClient service = new MyMvcProject.MyService.MyServiceClient();
MyMvcProject.MyService.MyComplexType result = service.MyServiceMethod(10,12);
安装于:
DAL.MyComplexType result = service.MyServiceMethod(10,12);
如何解决? 有什么问题?
已编辑
我的 vs 版本是 2013。
我在WPF项目中测试了这个方法,结果ok,这意味着服务没有创建自己的复杂类型并从DAL复杂类型中使用。
但在MVC 项目中,服务配置服务中的Reuse types in refrenced assemblies 选中和未选中都会创建自我复杂类型。
我不知道如何解决这个问题或者是什么原因?
【问题讨论】:
-
你为什么想要那个?
-
@AmitKumarGhosh,我想使用两种方法,包括服务和业务,并希望同时使用一种复杂类型的 DAL,而不是用于转换类型
标签: c# wcf model-view-controller