-
January 6th, 2009, 08:37 PM
#1
calling webservice from vb6 - no data returned
Hi...
I have a web service which is on the server machine. It will return arrays. Then i also have clients who will access this web service using an application in vb6. The problem is, sometimes the webservice failed to return any records. However if i try debug it from the server itself, it have several lines of data. To solve this problem, i need to ask the users to restart their PCs.
So, is there any other way to solve this issue such as command..to reset session maybe? etc?
Or am i missing something in my programme?
Thanks in advance.
-
January 6th, 2009, 09:08 PM
#2
Re: calling webservice from vb6 - no data returned
Might help if we could *SEE* your code.
Code:
' don't forget CODE TAGS
-
January 6th, 2009, 11:04 PM
#3
Re: calling webservice from vb6 - no data returned
Tq.
VB6 code
Code:
Public Sub gfnDisplayOpenInvoice()
.....
strUrl = "http://10.0.1.27/iposws/Service1.asmx"
strSoapAction = "http://tempuri.org/GetOpenInvoiceByAccountNo"
strXml = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<soap:Body>" & _
"<GetOpenInvoiceByAccountNo xmlns=""http://tempuri.org/"">" & _
"<accNo>" & Trim(Me.txtInput.Text) & "</accNo>" & _
"</GetOpenInvoiceByAccountNo>" & _
"</soap:Body>" & _
"</soap:Envelope>"
retVal = gfnPostWebserviceActno(strUrl, strSoapAction, strXml)
....
End Sub
Private Function gfnPostWebserviceActno(ByVal AsmxUrl As String, ByVal SoapActionUrl As String, ByVal XmlBody As String) As String
Dim objDom As Object
Dim objXmlHttp As Object
Dim strRet As String
Dim intPos1 As Integer
Dim intPos2 As Integer
On Error GoTo Err_PW
' Create objects to DOMDocument and XMLHTTP
Set objDom = CreateObject("MSXML2.DOMDocument")
Set objXmlHttp = CreateObject("MSXML2.XMLHTTP")
' Load XML
objDom.async = False
objDom.loadXML XmlBody
' Open the webservice
objXmlHttp.Open "POST", AsmxUrl, False
' Create headings
objXmlHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXmlHttp.setRequestHeader "SOAPAction", SoapActionUrl
' Send XML command
objXmlHttp.send objDom.xml
' Get all response text from webservice
strRet = objXmlHttp.responseText
' Close object
Set objXmlHttp = Nothing
' Extract result
intPos1 = InStr(strRet, "Result>") + 7
intPos2 = InStr(strRet, "</GetOpenInvoiceByAcco")
If intPos1 > 7 And intPos2 > 0 Then
strRet = Mid(strRet, intPos1, intPos2 - intPos1)
Else
strRet = ""
End If
' Return result
gfnPostWebserviceActno = strRet
Exit Function
Err_PW:
gfnPostWebserviceActno = "Error: " & Err.Number & " - " & Err.Description
End Function
Webservice
dbhelper.cs
Code:
using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
namespace MyCode
{
public class DbHelper
{
public static SqlConnection GetSqlConnection()
{
SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["config"].ToString());
return sqlCon;
}
public static void CreateCommand(string cmdTxt)
{
try
{
SqlCommand sqlCom = new SqlCommand();
sqlCom.Connection = GetSqlConnection();
if (sqlCom.Connection.State == ConnectionState.Closed)
sqlCom.Connection.Open();
sqlCom.CommandText = cmdTxt;
sqlCom.ExecuteNonQuery();
if (sqlCom.Connection.State == ConnectionState.Open)
sqlCom.Connection.Close();
sqlCom.Dispose();
//return Result;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//finally
//{
//}
}
public static SqlDataReader CreateReader(string cmdTXT)
{
try
{
SqlCommand sqlcmd=new SqlCommand();
sqlcmd.Connection = GetSqlConnection();
if (sqlcmd.Connection.State == ConnectionState.Closed)
sqlcmd.Connection.Open();
sqlcmd.CommandText = cmdTXT;
SqlDataReader sd = sqlcmd.ExecuteReader();
return sd;
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
public static List<string> getListOpenInvoiceByAccount(string account)
{
List<string> myList = new List<string>();
string cmdTXT = string.Format(@"select * from tblOpenInvoice where ActNo='{0}'", account);
SqlDataReader sd = CreateReader(cmdTXT);
while (sd.Read())
{
string str = sd["ActNo"].ToString() + "|" + sd["InvNo"].ToString() + "|" + sd["DocDate"].ToString() + "|" + sd["Amount"].ToString() + "|" + sd["CN"].ToString();
myList.Add(str);
}
sd.Close();
return myList;
}
public static List<string> getListOpenInvoiceByInvoice(string invoice)
{
List<string> myList = new List<string>();
string cmdTXT = string.Format(@"select * from tblOpenInvoice where InvNo='{0}'", invoice);
SqlDataReader sd = CreateReader(cmdTXT);
while (sd.Read())
{
string str = sd["ActNo"].ToString() + "|" + sd["InvNo"].ToString() + "|" + sd["DocDate"].ToString() + "|" + sd["Amount"].ToString() + "|" + sd["CN"].ToString();
myList.Add(str);
}
sd.Close();
return myList;
}
}
}
service1.asmx.cs
Code:
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Collections.Generic;
namespace MyCode
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string[] GetOpenInvoiceByAccountNo(string accNo)
{
List<string> myList=new List<string>();
myList = DbHelper.getListOpenInvoiceByAccount(accNo);
return myList.ToArray();
}
}
}
-
January 6th, 2009, 11:52 PM
#4
Re: calling webservice from vb6 - no data returned
Depending on how big the XML file is, VB6 may be the bottleneck, especially on older systems. It might even be timing out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|