2017-08-21 8 views
0

現在wcfサービスで作業しています。サービスはlocalhostを実行しています.Wcfサービスにはいくつかのメソッドがあります。私はlocalhostからメソッドにアクセスするときにいくつかのエラーに直面しています。たとえば、http://localhost:50028/StudentService.svc/GetAllStudent/ というエラーが表示されます。 ** WCFサービスメソッドが動作していません

**

Request Error 
The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service. 

ここでここで

[ServiceContract] 
    public interface IStudentService 
    { 

     [OperationContract] 
     [WebInvoke(Method = "GET", 
      RequestFormat = WebMessageFormat.Json, 
      ResponseFormat = WebMessageFormat.Json, 
      UriTemplate = "/GetAllStudent/")] 
     List<StudentDataContract> GetAllStudent(); 

     [OperationContract] 
     [WebGet(RequestFormat = WebMessageFormat.Json, 
      ResponseFormat = WebMessageFormat.Json, 
      UriTemplate = "/GetStudentDetails/{StudentId}")] 
     StudentDataContract GetStudentDetails(string StudentId); 

     [OperationContract] 
     [WebInvoke(Method = "POST", 
      RequestFormat = WebMessageFormat.Json, 
      ResponseFormat = WebMessageFormat.Json, 
      UriTemplate = "/AddNewStudent")] 
     bool AddNewStudent(StudentDataContract student); 

     [OperationContract] 
     [WebInvoke(Method = "PUT", 
      RequestFormat = WebMessageFormat.Json, 
      ResponseFormat = WebMessageFormat.Json, 
      UriTemplate = "/UpdateStudent")] 
     void UpdateStudent(StudentDataContract contact); 

     [OperationContract] 
     [WebInvoke(Method = "DELETE", 
      RequestFormat = WebMessageFormat.Json, 
      ResponseFormat = WebMessageFormat.Json, 
      UriTemplate = "DeleteStudent/{StudentId}")] 
     void DeleteStudent(string StudentId); 

    } 

} 

は、実装の私のコードです....私のコード形式WCFサービスです...

public class StudentService : IStudentService 
    { 
     StudentManagementEntities ctx; 

     public StudentService() 
     { 
      ctx = new StudentManagementEntities(); 
     } 

     public List<StudentDataContract> GetAllStudent() 
     { 
      //if (HttpContext.Current.Request.HttpMethod == "GetAllStudent") 
      // return null; 

      var query = (from a in ctx.Students 
         select a).Distinct(); 

      List<StudentDataContract> studentList = new List<StudentDataContract>(); 

      query.ToList().ForEach(rec => 
      { 
       studentList.Add(new StudentDataContract 
       { 
        StudentID = Convert.ToString(rec.StudentID), 
        Name = rec.Name, 
        Email = rec.Email, 
        EnrollYear = rec.EnrollYear, 
        Class = rec.Class, 
        City = rec.City, 
        Country = rec.Country 
       }); 
      }); 
      return studentList; 
     } 

     public StudentDataContract GetStudentDetails(string StudentId) 
     { 
      StudentDataContract student = new StudentDataContract(); 

      try 
      { 
       int Emp_ID = Convert.ToInt32(StudentId); 
       var query = (from a in ctx.Students 
          where a.StudentID.Equals(Emp_ID) 
          select a).Distinct().FirstOrDefault(); 

       student.StudentID = Convert.ToString(query.StudentID); 
       student.Name = query.Name; 
       student.Email = query.Email; 
       student.EnrollYear = query.EnrollYear; 
       student.Class = query.Class; 
       student.City = query.City; 
       student.Country = query.Country; 
      } 
      catch (Exception ex) 
      { 
       throw new FaultException<string> 
         (ex.Message); 
      } 
      return student; 
     } 

     public bool AddNewStudent(StudentDataContract student) 
     { 
      try 
      { 
       Student std = ctx.Students.Create(); 
       std.Name = student.Name; 
       std.Email = student.Email; 
       std.Class = student.Class; 
       std.EnrollYear = student.EnrollYear; 
       std.City = student.City; 
       std.Country = student.Country; 

       ctx.Students.Add(std); 
       ctx.SaveChanges(); 
      } 
      catch (Exception ex) 
      { 
       throw new FaultException<string> 
         (ex.Message); 
      } 
      return true; 
     } 

     public void UpdateStudent(StudentDataContract student) 
     { 
      try 
      { 
       int Stud_Id = Convert.ToInt32(student.StudentID); 
       Student std = ctx.Students.Where(rec => rec.StudentID == Stud_Id).FirstOrDefault(); 
       std.Name = student.Name; 
       std.Email = student.Email; 
       std.Class = student.Class; 
       std.EnrollYear = student.EnrollYear; 
       std.City = student.City; 
       std.Country = student.Country; 

       ctx.SaveChanges(); 
      } 
      catch (Exception ex) 
      { 
       throw new FaultException<string> 
         (ex.Message); 
      } 
     } 

     public void DeleteStudent(string StudentId) 
     { 
      try 
      { 
       int Stud_Id = Convert.ToInt32(StudentId); 
       Student std = ctx.Students.Where(rec => rec.StudentID == Stud_Id).FirstOrDefault(); 
       ctx.Students.Remove(std); 
       ctx.SaveChanges(); 
      } 
      catch (Exception ex) 
      { 
       throw new FaultException<string> 
         (ex.Message); 
      } 
     } 
    } 
} 

ここにweb.configファイルがあります。

私はその常にローカルホストからアクセスすることはできません10
<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5"> 
     <assemblies> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
    </compilation> 
    <httpRuntime targetFramework="4.5" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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> 
     <endpointBehaviors> 
     <behavior> 
      <webHttp helpEnabled="True"/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <protocolMapping> 
     <add binding="webHttpBinding" scheme="http" /> 
    </protocolMapping> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 


    <modules runAllManagedModulesForAllRequests="true" /> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 

    <directoryBrowse enabled="true" /> 
    </system.webServer> 
    <connectionStrings> 
    <add name="StudentManagementEntities" connectionString="metadata=res://*/SchoolManagement.csdl|res://*/SchoolManagement.ssdl|res://*/SchoolManagement.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=KHUNDOKARNIRJOR\KHUNDOKERNIRJOR;initial catalog=Student;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
</configuration> 

は、このエラー

リクエストエラー は、サーバがリクエストの処理中にエラーが発生した示しました。サービスへの有効なリクエストを作成するには、サービスのヘルプページを参照してください。ここで

私はあなたの設定ファイルの「サービス」の要素が表示されない...任意のヘルプは高く評価されます

答えて

0

Click here to see the out put

をしてくださいスクリーンショットです。サービスを設定するには、以下のリンクをご覧ください。 Configuring Services

もう1つの方法は、Visual Studioを使用してwcfサービスを作成することです。 Visual Studioは適切な設定ファイルを生成します。次に、それに応じてメソッド、インタフェース、設定を置き換えることができます。

あなたはリストを返そうとしています。私はリターンパラメータとしてListを渡すことはできないと思います。

+0

私は質問を更新しました – Rasel

0

uriTemplateから、してください 削除 "/" " http://localhost:50028/StudentService.svc" 上のすべてのメソッドに別の提案を確認してください。 "/ GetAllStudent /"の代わりに "GetAllStudent"と書いてください。

+0

申し訳ありませんが私はそれを変更しますが、同じ方法で応答します – Rasel

+0

Rasel、あなたのWeb設定ファイルも確認してください。サービスとビヘイビアタグが欠落していますが、 –

0
> <services> 
>  <service name="" behaviorConfiguration="serviceBehavior"> 
>   <endpoint address="" binding="webHttpBinding" contract="" behaviorConfiguration="web"/> 
>  </service> 
>  </services> 
>  <behaviors> 
>  <serviceBehaviors> 
>   <behavior name="serviceBehavior"> 
>   <serviceMetadata httpGetEnabled="true"/> 
>   <serviceDebug includeExceptionDetailInFaults="false"/> 
>   </behavior> 
>  </serviceBehaviors> 
>  <endpointBehaviors> 
>   <behavior name="web"> 
>   <webHttp/> 
>   </behavior> 
>  </endpointBehaviors> 
>  </behaviors> 

私はタグがWebConfigのから欠落しているサービスや行動がある見ています。

関連する問題