2012-11-30 2 views
0

내가 오류가 계속, WCF를 사용하여 편안한 서비스를 생성하고 제공하지 않았다WCF RESTful 서비스, 서버는 의미있는 응답

서버는 의미있는 답변을 제공하지 않았다을; 이는 계약 불일치, 조기 세션 종료 또는 내부 서버 오류로 인해 발생할 수 있습니다.

이것은 사용자 이름과 현재 시간을 가져 와서 로그 인/아웃을위한 데이터베이스에 저장하는 시간 시계 응용 프로그램입니다.

저는 REST 세계에 처음 오신 분 누구도 도와 드릴 수 있습니까?

내 서비스 인터페이스 :

ServiceContract(Namespace:="WCFRESTService")> _ 
Public Interface IService1 

<OperationContract()> _ 
<WebInvoke(UriTemplate:="/login", Method:="PUT")> _ 
Function InsertUserDetails(ByVal username As String, ByVal time As DateTime) As String 
End Interface 

서비스 코드 :

<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Required)> _ 
<ServiceBehavior(Namespace:="WCFRESTService")> _ 
Public Class Service1 
    Implements IService1 

    Private con As New SqlConnection("Data Source=TE-LAPTOP-001\SQL2008R2;Initial Catalog=timeClock;Integrated Security=True") 

    Public Function InsertUserDetails(ByVal username As String, ByVal time As DateTime) As String Implements IService1.InsertUserDetails 

     Dim strMessage As String = String.Empty 
     Dim errorMessage As String = String.Empty 
     Dim numcount As Integer = 0 

     numcount = getusercount(username) 
     If (numcount = 0) Then 

      Try 


       con.Open() 
       Dim cmd As New SqlCommand("spInsertLog", con) 
       cmd.CommandType = CommandType.StoredProcedure 

       cmd.Parameters.AddWithValue("@username", username) 
       cmd.Parameters.AddWithValue("@timein", time) 


       cmd.ExecuteNonQuery() 


      Catch ex As Exception 
       errorMessage = ex.ToString 
      Finally 
       con.Close() 
      End Try 

      strMessage = "You have Signed In at: " + time 
     ElseIf (numcount = 1) Then 

      strMessage = "Error: You need to SignOut before you can SignIn" 
     End If 


     Return errorMessage + strMessage 
    End Function 

    Public Function getusercount(ByVal username As String) As Integer 
     Dim count As Int32 = 0 
     Try 
      con.Open() 
      Dim cmd As New SqlCommand("spgetcount", con) 
      cmd.CommandType = CommandType.StoredProcedure 

      cmd.Parameters.AddWithValue("@username", username) 
      count = Convert.ToInt32(cmd.ExecuteScalar()) 


     Catch ex As Exception 
     Finally 
      con.Close() 
     End Try 


     Return count 
    End Function 
End Class 

내 클라이언트 코드

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Dim objervice As New ServiceReference1.Service1Client() 
    Dim result As String = objervice.InsertUserDetails("User1", DateTime.Now) 
    MsgBox(result) 
End Sub 

서비스 webconfig :

<system.serviceModel> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
<services> 
    <service name="WcfRESTService1.Service1" behaviorConfiguration="WcfRESTService1.Service1Behavior"> 
    <!-- Service Endpoints --> 
    <endpoint address="http://localhost:62131/Service1.svc" binding="webHttpBinding" contract="WcfRESTService1.IService1" behaviorConfiguration="web"> 
     <!-- 
      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> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 


<behaviors> 
    <serviceBehaviors> 
    <behavior name="WcfRESTService1.Service1Behavior"> 
     <!-- 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> 
    <endpointBehaviors> 
    <behavior name="web"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 
</system.serviceModel> 
01 23,516,

클라이언트 설정 :

<system.serviceModel> 
      <bindings> 
       <customBinding> 
       <binding name="WebHttpBinding_IService1"> 
        <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" 
        messageVersion="Soap12" writeEncoding="utf-8"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        </textMessageEncoding> 
        <httpTransport/> 
       </binding> 
       </customBinding> 
      </bindings> 
      <client> 

       <endpoint address="http://localhost:62131/Service1.svc" binding="customBinding" bindingConfiguration="WebHttpBinding_IService1" 
       contract="ServiceReference1.IService1" name="WebHttpBinding_IService1" /> 
      </client> 
       <behaviors> 
       <endpointBehaviors> 
        <behavior name="test"> 
        <webHttp /> 
        </behavior> 
       </endpointBehaviors> 
       </behaviors> 

</system.serviceModel> 

답변

0

당신은 (클라이언트의 같은 종류의) 여기 REST 필요가 없습니다. 은 그러나 당신이 원하는 경우 - 사용 스트림을 시도 REST 방식에서에서 WebGet이-응답 :

[OperationContract, WebGet(UriTemplate = "/SendMessage?login={login}&password={password}&phoneNum={phoneNum}&message={message}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]  
System.IO.Stream SendMessage(string login, string password, string phoneNum, string message, TimeSpan timeout); 
//.. 

public Stream SendMessage(string login, string password, string phoneNum, string message, TimeSpan timeout) 
{ 
//.. 
return new MemoryStream(Encoding.Default.GetBytes(jsonString)); 
}  
+0

그것은 일을 일부러. 하지만, "그런 종류의 고객에게"당신은 무엇을 의미합니까? 클라이언트가 무엇인지 언급 한 적이 없으며 버튼 클릭으로 나머지 서비스를 호출해야합니다. 나는 비누를 사용하여 똑같이 해왔다. 이제 나머지를 사용하려고한다. –