Advertisement
Guest User

Untitled

a guest
Apr 8th, 2012
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. 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...
  2.  
  3.  
  4. <?xml version="1.0" encoding="utf-8" ?>
  5. <configuration>
  6.  
  7. <system.web>
  8. <compilation debug="true" />
  9. </system.web>
  10. <!-- When deploying the service library project, the content of the config file must be added to the host's
  11. app.config file. System.Configuration does not support config files for libraries. -->
  12. <system.serviceModel>
  13. <services>
  14. <service name="MyJobs.JobsSvc">
  15. <endpoint address="" binding="wsHttpBinding" contract="MyJobs.IJobsSvc">
  16. <identity>
  17. <dns value="localhost" />
  18. </identity>
  19. </endpoint>
  20. <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  21. <host>
  22. <baseAddresses>
  23. <add baseAddress="http://localhost:8732/Design_Time_Addresses/Jobs/MyJobs/" />
  24. </baseAddresses>
  25. </host>
  26. </service>
  27. </services>
  28. <behaviors>
  29. <serviceBehaviors>
  30. <behavior>
  31. <!-- To avoid disclosing metadata information,
  32. set the value below to false and remove the metadata endpoint above before deployment -->
  33. <serviceMetadata httpGetEnabled="True"/>
  34. <!-- To receive exception details in faults for debugging purposes,
  35. set the value below to true. Set to false before deployment
  36. to avoid disclosing exception information -->
  37. <serviceDebug includeExceptionDetailInFaults="False" />
  38. </behavior>
  39. </serviceBehaviors>
  40. </behaviors>
  41. </system.serviceModel>
  42.  
  43. </configuration>
  44.  
  45.  
  46. namespace MyJobs
  47. {
  48. [ServiceContract]
  49. public interface IJobsSvc
  50. {
  51. [OperationContract]
  52. DataSet GetJobs();
  53.  
  54. [OperationContract]
  55. Job GetJobInfo(int JobId);
  56.  
  57. [OperationContract]
  58. List<Job> GetAllJobs();
  59. }
  60. }
  61.  
  62.  
  63.  
  64. namespace MyJobs
  65. {
  66. [DataContract]
  67. public class Job
  68. {
  69. [DataMember]
  70. public int JobId { get; set;}
  71.  
  72. [DataMember]
  73. public string Description{get;set;}
  74.  
  75. [DataMember]
  76. public int MinLevel { get; set; }
  77.  
  78. [DataMember]
  79. public int MaxLevel { get; set; }
  80. }
  81. }
  82.  
  83.  
  84.  
  85.  
  86. namespace MyJobs
  87. {
  88. public class JobsSvc:IJobsSvc
  89. {
  90.  
  91. #region IJobsSvc Members
  92.  
  93. public System.Data.DataSet GetJobs()
  94. {
  95. string str = @"data source=PERSONAL-659BE4;database=practice;integrated security=true";
  96. DataSet ds = new DataSet();
  97. SqlConnection cn = new SqlConnection(str);
  98. SqlDataAdapter da = new SqlDataAdapter("select * from Job1",cn);
  99. da.Fill(ds);
  100. return ds;
  101.  
  102. }
  103.  
  104. public Job GetJobInfo(int JobId)
  105. {
  106. string str = @"data source=PERSONAL-659BE4;database=practice;integrated security=true";
  107. SqlConnection cn = new SqlConnection(str);
  108. SqlCommand cmd = new SqlCommand("select * from Job1 where JobId="+JobId,cn);
  109. cn.Open();
  110. SqlDataReader dr = cmd.ExecuteReader();
  111. Job obj = new Job();
  112. if (dr.Read())
  113. {
  114. obj.JobId = JobId;
  115. obj.Description = dr[1].ToString();
  116. obj.MinLevel = Convert.ToInt32(dr[2]);
  117. obj.MaxLevel = Convert.ToInt32(dr[3]);
  118. }
  119. else
  120. {
  121. obj.JobId = -1;
  122. }
  123. return obj;
  124. }
  125.  
  126. public List<Job> GetAllJobs()
  127. {
  128. throw new NotImplementedException();
  129. }
  130.  
  131. #endregion
  132. }
  133. }
  134.  
  135.  
  136. My WPF client is as follows--
  137.  
  138. namespace WPFUsingWCFJobService
  139. {
  140. /// <summary>
  141. /// Interaction logic for MainWindow.xaml
  142. /// </summary>
  143. public partial class MainWindow : Window
  144. {
  145. public MainWindow()
  146. {
  147. InitializeComponent();
  148. }
  149.  
  150. private void button1_Click(object sender, RoutedEventArgs e)
  151. {
  152. ServiceReference1.JobsSvcClient obj = new ServiceReference1.JobsSvcClient();
  153. dataGrid1.ItemsSource = obj.GetJobs().Tables[0].DefaultView;
  154. }
  155. }
  156. }
  157.  
  158. PLs help me
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement