Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I have created a wcf service and i am unable to consume it by a wpf client. I am providing the details. pls check it out & help me...
- <?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <system.web>
- <compilation debug="true" />
- </system.web>
- <!-- When deploying the service library project, the content of the config file must be added to the host's
- app.config file. System.Configuration does not support config files for libraries. -->
- <system.serviceModel>
- <services>
- <service name="MyJobs.JobsSvc">
- <endpoint address="" binding="wsHttpBinding" contract="MyJobs.IJobsSvc">
- <identity>
- <dns value="localhost" />
- </identity>
- </endpoint>
- <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
- <host>
- <baseAddresses>
- <add baseAddress="http://localhost:8732/Design_Time_Addresses/Jobs/MyJobs/" />
- </baseAddresses>
- </host>
- </service>
- </services>
- <behaviors>
- <serviceBehaviors>
- <behavior>
- <!-- To avoid disclosing metadata information,
- set the value below to false and remove the metadata endpoint above before deployment -->
- <serviceMetadata httpGetEnabled="True"/>
- <!-- 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>
- </configuration>
- namespace MyJobs
- {
- [ServiceContract]
- public interface IJobsSvc
- {
- [OperationContract]
- DataSet GetJobs();
- [OperationContract]
- Job GetJobInfo(int JobId);
- [OperationContract]
- List<Job> GetAllJobs();
- }
- }
- namespace MyJobs
- {
- [DataContract]
- public class Job
- {
- [DataMember]
- public int JobId { get; set;}
- [DataMember]
- public string Description{get;set;}
- [DataMember]
- public int MinLevel { get; set; }
- [DataMember]
- public int MaxLevel { get; set; }
- }
- }
- namespace MyJobs
- {
- public class JobsSvc:IJobsSvc
- {
- #region IJobsSvc Members
- public System.Data.DataSet GetJobs()
- {
- string str = @"data source=PERSONAL-659BE4;database=practice;integrated security=true";
- DataSet ds = new DataSet();
- SqlConnection cn = new SqlConnection(str);
- SqlDataAdapter da = new SqlDataAdapter("select * from Job1",cn);
- da.Fill(ds);
- return ds;
- }
- public Job GetJobInfo(int JobId)
- {
- string str = @"data source=PERSONAL-659BE4;database=practice;integrated security=true";
- SqlConnection cn = new SqlConnection(str);
- SqlCommand cmd = new SqlCommand("select * from Job1 where JobId="+JobId,cn);
- cn.Open();
- SqlDataReader dr = cmd.ExecuteReader();
- Job obj = new Job();
- if (dr.Read())
- {
- obj.JobId = JobId;
- obj.Description = dr[1].ToString();
- obj.MinLevel = Convert.ToInt32(dr[2]);
- obj.MaxLevel = Convert.ToInt32(dr[3]);
- }
- else
- {
- obj.JobId = -1;
- }
- return obj;
- }
- public List<Job> GetAllJobs()
- {
- throw new NotImplementedException();
- }
- #endregion
- }
- }
- My WPF client is as follows--
- namespace WPFUsingWCFJobService
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, RoutedEventArgs e)
- {
- ServiceReference1.JobsSvcClient obj = new ServiceReference1.JobsSvcClient();
- dataGrid1.ItemsSource = obj.GetJobs().Tables[0].DefaultView;
- }
- }
- }
- PLs help me
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement