Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have dataset.xsd on which i put my tableadapters,when i compiling wcf service compiler give mistake

"A namespace cannot directly contain members such as fields or methods"..

I use this tableadapters to access their methods and properies in unit service.cs .

Can you help me..


C#
public Address GetAdr(int id)
        {
            Address ad = new Address();
            
            adrt.Connection.ConnectionString = con;
            adrt.Connection.Open();

            
           //adr.FindByADR_ID(id);
            ad.City = adrt.Connection.State.ToString();
            

            return ad;
        }
Posted
Updated 21-Jun-12 1:40am
v3
Comments
lukeer 21-Jun-12 7:29am    
You nicely tagged your question and provided the full error message. That's fine.
Now please use the "Improve question" link to add the part of your code where the error is being reported. Mark the exact line.
bbirajdar 21-Jun-12 7:34am    
You are missing a opening '{' in your WCF class

1 solution

You get this error because you have put this method in a namespace and not in a class..


using System;

namespace yourNameSpace
{
   class yourClass
    {
        public Address GetAdr(int id)
        {
            Address ad = new Address();
            
            adrt.Connection.ConnectionString = con;
            adrt.Connection.Open();
 
            
           //adr.FindByADR_ID(id);
            ad.City = adrt.Connection.State.ToString();
            
 
            return ad;
        }
    }
}


Please follow this sequence then check it out..!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900