日期:2014-05-18  浏览次数:21037 次

#标题党#请问关于WebService的一些问题!
警告,本主题标题违反论坛关于标题党的规定,这一次我帮你改了,下一次就是直接删除。

原标题:困扰菜鸟界多年的问题,欢迎高手解答,这个问题在招聘市场大概值5000。


同时需要说明的是,如果同时有多个问题需要解答,请分别提问。






一个webWeb service的类
C# code

using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Threading;
using System.Runtime.Remoting.Messaging;

public delegate int Comuter(int a, int b);

public delegate void DivCompleteHandler(object sender, DivCompleteEventArgs e);

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class DivideService : System.Web.Services.WebService
{
    public event DivCompleteHandler OnDivComplete;


    public DivideService()
    {

    }

    [WebMethod]
    public int Div(int a, int b)
    {
        Thread.Sleep(10000);

        try
        {
            return a / b;
        }
        catch (DivideByZeroException e)
        {
            throw e;
        }
    }

    [WebMethod]
    public  void DivAsyn(int a, int b)
    {
        Comuter computer = new Comuter(this.Div);
        computer.BeginInvoke(a, b, new AsyncCallback(Response), null);
    }

     void Response(IAsyncResult result)
    {
        try
        {
            Comuter computer = ((AsyncResult)result).AsyncDelegate as Comuter;

            if (null != computer)
            {
                int consult = computer.EndInvoke(result);
                OnDivComplete(this, new DivCompleteEventArgs(consult, null, false, null));
            }
        }
        catch (DivideByZeroException e)
        {
            OnDivComplete(this, new DivCompleteEventArgs(0, e, true, null));
        }
        catch (Exception e)
        {
            OnDivComplete(this, new DivCompleteEventArgs(0, e, true, null));
        }

    } 
}



------解决方案--------------------
up
------解决方案--------------------
up
------解决方案--------------------
为5000块标记一下
------解决方案--------------------
标题党
------解决方案--------------------
为5000美元也标记一下
------解决方案--------------------
不会吧!
------解决方案--------------------
UP
------解决方案--------------------
mark
------解决方案--------------------
5000美刀?