我有一个经典的asp.net Web服务(asmx)和一个web方法.我需要在我的web方法中为某些情况抛出一个自定义异常,我需要捕获特定的自定义异常,我调用Web服务方法.
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public HelloWorldOutput HelloWorld(HelloWorldInput input)
{
try
{
// My Code
return new HelloWorldOutput();
}
catch (Exception ex)
{
throw new HelloWorldException("Hello World Exception", ex);
}
}
}
Run Code Online (Sandbox Code Playgroud)
输入,输出和异常类作为示例:
public class HelloWorldInput { }
public class HelloWorldOutput { }
[Serializable]
public class HelloWorldException : Exception
{
public HelloWorldException() { }
public HelloWorldException(string message) : base(message) { }
public HelloWorldException(string message, Exception inner)
: base(message, inner) { …Run Code Online (Sandbox Code Playgroud) 我有一个具有数值的项目列表,我需要使用这些项目来实现总和.我需要你的帮助来构建这样的算法.下面是一个用C#编写的描述我的问题的示例:
int sum = 21;
List<Item> list = new List<Item>();
list.Add(new Item() { Id = Guid.NewGuid(), Value = 3 });
list.Add(new Item() { Id = Guid.NewGuid(), Value = 5 });
list.Add(new Item() { Id = Guid.NewGuid(), Value = 12 });
list.Add(new Item() { Id = Guid.NewGuid(), Value = 3 });
list.Add(new Item() { Id = Guid.NewGuid(), Value = 2 });
list.Add(new Item() { Id = Guid.NewGuid(), Value = 7 });
List<Item> result = // the items in the list that …Run Code Online (Sandbox Code Playgroud) 我将在我的应用程序中使用Entity Framework和WCF.正如我所看到的,建议的做法是使用POCO和Entity Framework,并使用POCO类作为DataContracts.这实际上是POCO和属性的用途,如果我没有错的话.
但是我被要求对Entity Framework POCO和WCF DataContracts使用单独的分类.并在POCO和DataContracts之间使用映射器.喜欢,Foo并FooContract具有相同的属性.
我是第一种方法,但我想知道第二种方法(单独的类方法)是否为应用程序提供了灵活性,或者只是浪费了精力.
如果您能分享您对POCO和DataContracts使用单独课程的想法和经验,对此有利,我将不胜感激.
c# ×2
.net ×1
algorithm ×1
asp.net ×1
combinations ×1
datacontract ×1
exception ×1
list ×1
poco ×1
wcf ×1
web-services ×1