2013-11-25 57 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(命名空間)」。