Method Community

 

Problems with Web Service API Call

Last post 07-03-2012 1:48 PM by DaveS. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-02-2012 5:53 PM

    • DaveS
    • Top 50 Contributor
    • Joined on 07-02-2009
    • Boulder, Colorado
    • Posts 87

    Problems with Web Service API Call

    Our Method Integration API calls are not always working.   It sometimes works for about 24 hours, then stops working.  It returns the following error message.

    "The underlying connection was closed: Could not establish trust relationship with remote server.The underlying connection was closed: Could not establish trust relationship with remote server.0Therre was an error with the methods API call."

    We have used both HTTP and HTTPS, and one of the other sometimes work. 
    We are using Visual Studios 2005, ASP.Net 

    These are the urls we use to get to the Web Services directory:
    https://www.methodintegration.com/MethodAPI/service.asmx
    http://www.methodintegration.com/MethodAPI/service.asmx

    The code that we use for the API calls are shown below.

    Questions:
    1    Method API documentation suggests using HTTPS, is that still true?
    2.   Is there a limit to the # of API calls such as 1000 per day/ week/ month?
    3.   Why are the Method API calls not working and what can we do to get them to work reliably.

        Dave 
    ----------------------------------------

    Dim wbsMethodAPI As New com.methodintegration.www.Service 'MethodAPI.Service
    Dim sResult As String 'tells us Success or error
    Dim datResponse As Data.DataSet = Nothing
    Dim sCompanyAccount As String
    Dim sUserName As String
    Dim sPassword As String
    sCompanyAccount = Session("mlogon")
    sUserName = Session("muname")
    sPassword = Session("mpw")
    Dim sSelectFields As String
    Dim sSelectFrom As String
    Dim sSelectWhere As String
    Dim sSelectGroupBy As String
    Dim sSelectHaving As String
    Dim sSelectOrderBy As String

    sSelectFields = "account,accounttxn,txntype,accountnumber,txnrecordid,ispostedtoaccounting,amount,txndate,txndetailrecordid"
    sSelectFrom = "transaction"

    sSelectWhere = "account='" & saccount & "' and ispostedtoaccounting =1 and txndate >= '" & Session("Fstartdate") & " 12:00:00 AM' and txndate <= '" & Session("Ftodate") & " 11:59:59 PM'"
    'txndate >= '" & mydate & " 12:00:00 AM' and txndate <= '" & mydate2 & " 11:59:59 PM'"

    sSelectGroupBy = ""
    sSelectHaving = ""
    sSelectOrderBy = ""
    'Call the MethodAPI to get the dataset
    sResult = wbsMethodAPI.MethodAPISelect_DataSet(sCompanyAccount, sUserName, sPassword, _
    datResponse, sSelectFrom, sSelectFields, sSelectWhere, sSelectGroupBy, sSelectHaving, sSelectOrderBy)
    wbsMethodAPI = Nothing
    If sResult.Trim.ToUpper.StartsWith("Success".ToUpper) = False Then
    'failed, give a message
    Response.Write(sResult)
    merror = 1
    Exit Sub
    End If

     

     

    Dave Sakamoto CPA, MBA
    Founder and CEO Info On The Web
    Dave.Sakamoto@InfoOnTheWeb.com
  • 07-03-2012 8:39 AM In reply to

    Re: Problems with Web Service API Call

    Answer

     Hi DaveS,

    "1 Method API documentation suggests using HTTPS, is that still true?"

    Yes

    "2. Is there a limit to the # of API calls such as 1000 per day/ week/ month?"

    No there is not....as long as your login credentials are valid use away

    "3. Why are the Method API calls not working and what can we do to get them to work reliably."

    This one is a little trickier....what it comes down to is there may be a problem with your application trusting our ssl certificate. When you browse the web and you get this issue you, you get a prompt asking you something like "Do you want to accept/trust the cert, etc.". You don't get this prompt in a webservice call.

    For this specific issue, what you need to do is create your own Certificate policy class that implements the ICertificatePolicy interface.

    I'll post the examples from the following article http://support.microsoft.com/kb/823177 You can also find out more by doing a google search for "The underlying connection was closed: Could not establish trust relationship with remote server"

    VB

    Imports System.Net
    Imports System.Security.Cryptography.X509Certificates
    Public Class MyPolicy
      Implements ICertificatePolicy

      Public Function CheckValidationResult(ByVal srvPoint As ServicePoint, _
                    ByVal cert As X509Certificate, ByVal request As WebRequest, _
                    ByVal certificateProblem As Integer) _
                As Boolean Implements ICertificatePolicy.CheckValidationResult
        'Return True to force the certificate to be accepted.
        Return True
      End Function
    End Class

    C#

    using System.Net;
    using System.Security.Cryptography.X509Certificates;

    public class MyPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
              ServicePoint srvPoint
            , X509Certificate certificate
            , WebRequest request
            , int certificateProblem) {

            //Return True to force the certificate to be accepted.
            return true;

        } // end CheckValidationResult
    } // class MyPolicy

     

    Before the webservice call is invoked you need to execute the following

    VB

    System.Net.ServicePointManager.CertificatePolicy = New MyPolicy()

    C#

    System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();

     

    Dave

  • 07-03-2012 9:41 AM In reply to

    Re: Problems with Web Service API Call

     HI DaveS

    Following up a little more on this, we should also point out that we have no other users reporting this. We also use the API on a regular basis for many of our applications and internal functions and have never encountered this problem, nor have we had to resort to implementing Microsoft’s certificate policy code above.  So, while the above solution may work for you, the source of the problem may have been just a corrupt cache on your browser (out of our control), corrupt cache of certificates at your ISP or firewall level (out of our control), or a corrupt web reference by your app in visual studio (worth removing the reference entirely, and re-adding it from scratch with a new name).

    Dave

  • 07-03-2012 1:48 PM In reply to

    • DaveS
    • Top 50 Contributor
    • Joined on 07-02-2009
    • Boulder, Colorado
    • Posts 87

    Re: Problems with Web Service API Call

     Hi David

    Thank you for both of your replies on my Forum posting about problems with Web Service APIs calls.  Very helpful.  I have passed them on to my IT staff and we'll follow your instructions and suggestions and try to get the problems resolved.   I'll let you know if I have other findings or questions.

       Dave Sakamoto

    Dave Sakamoto CPA, MBA
    Founder and CEO Info On The Web
    Dave.Sakamoto@InfoOnTheWeb.com
Page 1 of 1 (4 items)