开发者

Can only access Web Service namespace through User Controls, not plain C# classesm, in Silverlight [closed]

开发者 https://www.devze.com 2023-04-12 03:09 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

Closed 8 years ago.

Imp开发者_JAVA百科rove this question

I'm not sure why I'm having this problem, but I can only talk to my web service through a User Control or App.xaml.cs. I'm trying to use the service in a simple data oriented class so I didn't want to use a User Control.

This compiles fine:

//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();
....

This does not:

//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 reports "Expected class, delegate, enum..." for any reference to SharepointWS.SharepointWebServiceSoapClient.

I'm using the same steps listed here:

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

My web service's namespace is Sharepoint_Integration_Project.SharepointWS and I've tried fully qualifying it and that hasn't helped.

Any suggestions are appreciated, thanks!


You have a field declaration outside of the class declaration. Can't do that.

Change:

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

    public class Controller
    {

    }
}

to:

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

    }
}


You cannot have fields/functions/anything other than class/struct outside of classes/structs:

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

If you it to be global, you can use static class: (and to be usable you should probably remove prive)

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

精彩评论

暂无评论...
验证码 换一张
取 消