我不知道为什么我有这个问题,但我只能通过用户控件或App.xaml.cs与我的web服务交谈。我试图在一个简单的面向数据的类中使用服务,所以我不想使用用户控件。
这个编译得很好:
//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();
....
//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报告"Expected class, delegate, enum…"对于任何sharepointtws . sharepointwebservicesoapclient的引用。
我使用这里列出的相同步骤:
http://www.silverlightshow.net/items/consuming - asmx - web -服务-与- silverlight 2. aspx
我的web服务的命名空间是Sharepoint_Integration_Project。sharepointtws和我都试过完全限定它,但没有任何帮助。任何建议都是赞赏的,谢谢!
在类声明之外有一个字段声明。不能那样做。
改变:
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();
}
}
在类/结构之外不能有字段/函数/除了类/结构之外的任何东西:
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
}
}