title: WCF Service Method POST and GET in ASP.NET
body: <p>i have a two program, first the asp.net and the second is WCF Service.
  the code below is on asp.net program.</p>
  
  <pre><code>Public Function GetDataSource(ByVal prmModule As Object, ByVal prmEndPointName As String)
      Dim strEndPoint As String = GetEndPoint(prmEndPointName)
      Dim wr As WebRequest = WebRequest.Create(strEndPoint &amp; prmModule)
      Dim ws As WebResponse = wr.GetResponse
      Dim enc As Encoding = System.Text.Encoding.GetEncoding(1252)
      Dim rs As New StreamReader(ws.GetResponseStream)
      Dim response As String = rs.ReadToEnd
      rs.Close()
      Return response
  End Function
  
  Public Sub SendClientData(ByVal prmEndPoint As String, ByVal prmModule As String, ByVal prmSource As String)
      Dim request As HttpWebRequest
      Dim response As HttpWebResponse = Nothing
      Dim address As Uri
      Dim data As StringBuilder
      Dim byteData() As Byte
      Dim postStream As Stream = Nothing
  
      ' Set the REST API URL
      address = New Uri(GetEndPoint(prmEndPoint) &amp; prmModule)
      ' Create the web request
      request = DirectCast(WebRequest.Create(address), HttpWebRequest)
  
      ' Set type to POST  
      request.Method = "POST"
      request.ContentType = "application/x-www-form-urlencoded"
  
      ' Create the data we want to send (each data.Append is for specific paramater data) 
      data = New StringBuilder()
      data.Append(prmSource)
      ' Create a byte array of the data we want to send  
      byteData = UTF8Encoding.UTF8.GetBytes(data.ToString())
  
      ' Set the content length in the request headers  
      request.ContentLength = byteData.Length
  
      Try
          postStream = request.GetRequestStream()
          postStream.Write(byteData, 0, byteData.Length)
      Finally
          If Not postStream Is Nothing Then postStream.Close()
      End Try
  End Sub
  </code></pre>
  
  <p>the above code is the function, GetDataSource is used to GET Method and the SendClientData is used to POST Method.</p>
  
  <pre><code>&lt;OperationContract()&gt; _
  &lt;WebInvoke(Method:="POST", _
         ResponseFormat:=WebMessageFormat.Json, _
         BodyStyle:=WebMessageBodyStyle.Wrapped, _
         UriTemplate:="applicant/post")&gt; _
  Sub postApplicant(ByVal request As Stream)
  
  &lt;OperationContract()&gt; _
  &lt;WebInvoke(Method:="GET", _
         ResponseFormat:=WebMessageFormat.Json, _
         BodyStyle:=WebMessageBodyStyle.Wrapped, _
         UriTemplate:="applicant/search/{firstname}/{lastname}/{dateofbirth}/{placeofbirth}")&gt; _
  Function getApplicantHaermes(ByVal firstname As String, ByVal lastname As String, ByVal dateofbirth As String, ByVal placeofbirth As String) As String
  </code></pre>
  
  <p>the code above is on WCF Service, its used to call the function that implemented.</p>
  
  <p>here's the main question:</p>
  
  <pre><code>        Dim arr As New ArrayList : arr.Add("Id")
          Dim dt As New DataTable
          Dim tempDT As New DataTable
          tempDT = (AddPhoneNumberToDataTable(obj))
          If Session("EditPhoneNumber") IsNot Nothing Then
              SendClientData(EMPLOYEEENDPOINT, "phonenumber/postupdate/" &amp;                   obj.HaermesOid, GetJsonFromDataTable(tempDT))
          Else
              SendClientData(EMPLOYEEENDPOINT, "phonenumber/post", GetJsonFromDataTable(tempDT))
  
              dt = AssignToDataTable(GetDataSource("phonenumber/search/" &amp; obj.Party.Oid.ToString &amp; "/" &amp; obj.PhoneType.ToString &amp; _
                                               "/" &amp; obj.Number.ToString, EMPLOYEEENDPOINT), arr)
  
              With obj
                  .HaermesOid = dt(0)("Id")
                  .Save()
              End With
          End If
  </code></pre>
  
  <p>when i call the SendClientData from ASP.Net to call WCF service for posting some data, the code below (Function GetDataSoucre) is for Get data from WCF to ASP.Net, but when i call the SendClientData the function that implemented is running, its not even finished yet then the GET Function already running, its make two function running at the same time. The GET Method is getting the data from the POST Method, so in the end the GET Method didn't get the data. </p>