2011-10-11 16 views
-1

我不確定爲什麼我遇到此問題,但我只能通過用戶控件或App.xaml與我的Web服務通信的.cs。我試圖在簡單的面向數據的類中使用該服務,所以我不想使用用戶控件。只能在Silverlight中通過用戶控件訪問Web Service名稱空間,而不是純C#classesm

這種精細編譯:

//App.xaml.cs 
<using statements...> 

namespace Sharepoint_Integration_Project 
{ 
    public partial class App : Application 
    { 
     private SharepointWS.SharepointWebServiceSoapClient SpWSSoap 
      = new SharepointWS.SharepointWebServiceSoapClient(); 

     public App() 
     { 
      this.Startup += this.Application_Startup; 
      this.UnhandledException += this.Application_UnhandledException; 

      InitializeComponent(); 
.... 

這不:凡提述SharepointWS.SharepointWebServiceSoapClient

//Controller.cs 
<using statements copied from App.xml.cs...> 

namespace Sharepoint_Integration_Project 
{ 
    private SharepointWS.SharepointWebServiceSoapClient SpWSSoap 
     = new SharepointWS.SharepointWebServiceSoapClient(); 

    public class Controller 
    { 

    } 
} 

Visual Studio的報告 「預期類,委託,枚舉...」。

我使用這裏列出的相同步驟:

http://www.silverlightshow.net/items/Consuming-ASMX-Web-Services-with-Silverlight-2.aspx

我的Web服務的命名空間是Sharepoint_Integration_Project.SharepointWS我嘗試了完全限定它,這並沒有幫助。

任何建議表示讚賞,謝謝!

+0

題外話 - 這是一個簡單的打字錯誤 - 並不會有助於未來SO用戶。 – arserbin3

回答

0

您有一個字段聲明之外的類聲明。不能這樣做。

變化:

namespace Sharepoint_Integration_Project 
{ 
    private SharepointWS.SharepointWebServiceSoapClient SpWSSoap 
     = new SharepointWS.SharepointWebServiceSoapClient(); 

    public class Controller 
    { 

    } 
} 

到:

namespace Sharepoint_Integration_Project 
{ 
    public class Controller 
    { 
     private SharepointWS.SharepointWebServiceSoapClient SpWSSoap 
      = new SharepointWS.SharepointWebServiceSoapClient(); 

    } 
} 
0

你不能有田/班/結構之外的功能/除2級以外的任何/結構:

namespace Sharepoint_Integration_Project 
{ 
    private SharepointWS.SharepointWebServiceSoapClient SpWSSoap 
     = new SharepointWS.SharepointWebServiceSoapClient(); // outside of class 
} 

如果它是全球性的,你可以使用靜態類:(和爲可用,你應該可能刪除prive)

namespace Sharepoint_Integration_Project 
{ 
    static class Name 
    { 
     private static SharepointWS.SharepointWebServiceSoapClient SpWSSoap 
      = new SharepointWS.SharepointWebServiceSoapClient(); // inside of class 
    } 
} 
相關問題