Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
CSS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ServiceModel;


namespace WCFTemplateExample
{
    [ServiceContract]
    interface WCFInterface
    {
        [OperationContract]
        DataSet GetData();

    }
}


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace WCFTemplateExample
{
   public  class WCFClass :WCFInterface 
    {
        #region WCFInterface Members

        public System.Data.DataSet GetData()
        {
            SqlConnection con = new SqlConnection(@"Data Source=iicss20\PMIS;Initial Catalog=MSSLMS;Persist Security Info=True;User ID=nkhn3059;Password=nkhn3059");
            SqlDataAdapter da = new SqlDataAdapter("select * from ss.lease",con);
            DataSet ds = new DataSet();
            da.Fill(ds, "ss.lease");
            return ds;

        }

        #endregion
    }
}



XML
<system.serviceModel>
    <services>
      <service name="WCFTemplateExample.WCFClass" behaviorConfiguration="WCFTemplateExample.WCFClassBehavior">
        <host>
          <baseAddresses>
            <add baseAddress = "net.tcp://localhost:8731/Design_Time_Addresses/WCFTemplateExample/WCFClass/" />
          </baseAddresses>
        </host>
        <endpoint address="net.tcp://localhost:8008/WCFClass" binding="netTcpBinding" contract="WCFTemplateExample.WCFInterface"></endpoint>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <!--<endpoint address ="" binding="Binding" contract="WCFTemplateExample.WCFInterface">
          --><!--

              Upon deployment, the following identity element should be removed or replaced to reflect the
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity
              automatically.
          --><!--
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>-->
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WCFTemplateExample.WCFClassBehavior">
          <!-- To avoid disclosing metadata information,
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="false"/>
          <!-- To receive exception details in faults for debugging purposes,
          set the value below to true.  Set to false before deployment
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>


It's not return the Service method which contains DataSet..
Posted
Updated 16-Aug-12 19:29pm
v3
Comments
StianSandberg 16-Aug-12 7:19am    
what does it return?

Dont use dataset in WCF services. Use Collection or dataclasses.

Check this to know why we shouldnt use Dataset as return type in WCF service contract.

http://www.hanselman.com/blog/ReturningDataSetsFromWebServicesIsTheSpawnOfSatanAndRepresentsAllThatIsTrulyEvilInTheWorld.aspx[^]

If you still want to use, then check these links

1. http://www.silverlighthostingnews.com/index.php/archives/461[^]

2. http://jwalin.wordpress.com/2011/03/16/passing-large-dataset-to-webwcf-service/[^]
 
Share this answer
 
SqlConnection con = new SqlConnection(@"Data Source=iicss20\PMIS;Initial Catalog=MSSLMS;Persist Security Info=True;User ID=nkhn3059;Password=nkhn3059");

SqlDataAdapter adapter = new SqlDataAdapter();
adapter.TableMappings.Add("Table", "lease");
con.Open();
SqlCommand command = new SqlCommand(
"SELECT * FROM ss.lease;",
connection);
command.CommandType = CommandType.Text;
adapter.SelectCommand = command;

adapter.Fill(dataSet);

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