2013-11-25 129 views
2

我有一个WebMethod返回类型是double []的问题。我试图在窗体中访问此方法,但结果如下:WebMethod c#return double []

对操作“FIR”的回复消息主体进行反序列化时出错。预期的命名空间'http://google.com/'的结尾元素'FIRResult'。从命名空间'http://google.com/'找到元素'double'。 1号线位置278

示例代码:

private void submit_Click(object sender, EventArgs e) 
     { 
      int N = int.Parse(textBox1.Text); 
      int fN = int.Parse(textBox6.Text); 
      int fS = int.Parse(textBox5.Text); 
      int rippleLimit = int.Parse(textBox4.Text); 

      double[] result = ws.FIR(N, (double)fN, (double)fS, rippleLimit); 


      this.Hide(); 
     } 


[WebMethod] 
     public double[] FIR(int N, double fs, double fn, int rippleLimit) 
     { 

      double rippleDev; 
      List<double> result = new List<double>(); 

      List<double> signal = firDesign(N, fn, fs); 
      DTFT(signal, N, fs, fn, 1); 

      List<double> moduledSignal = moduleSignal(Service1.real, Service1.img); 

      rippleDev = calculateRippleDev(fn, moduledSignal); 

      result.Add(rippleDev); 

     for (int i = 0; i < moduledSignal.Count; i++) 
     { 
      result.Add(moduledSignal[i]); 
     } 


     return result.ToArray(); 
    } 
+0

我们可以看到javascript调用web方法吗? – MadSkunk

回答

0

Web方法必须static,请尝试:

[WebMethod] 
public static double[] FIR(int N, double fs, double fn, int rippleLimit) 
... 
+0

Are you sure?Microsoft use'[WebMethod]'in an non-static context。http: //msdn.microsoft.com/en-us/library/byxd99hx(v=vs.90).aspx –

+0

奇怪的是,我需要正确阅读该链接,但是webmethods是静态的,请参阅http:// s tackoverflow.com/questions/1360253/call-non-static-method-in-server-sideaspx-cs-from-client-side-use-javascript – MadSkunk

+0

我想你/我们将Web服务与PageMethods混淆了,你试图创建? (都使用[WebMethod]属性)我们需要查看更多的代码,服务器端和客户端。 – MadSkunk

0

我已经试过了静态,但现在它有这个问题.. 。 System.Web.Services.Protocols.SoapException:服务器无法识别HTTP Header SOAPAction的值:http://google.com/FIR。 在System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() 在System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage消息)

在窗体时,我调用方法Web方法

+1

我们需要看到更多的代码!你怎么称呼这个方法? http://google.com来自哪里!? – MadSkunk

-1

WWW .google.com来自命名空间“[WebService(命名空间)”。