Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Wednesday, March 28, 2012

Web server time

can anyone please tell me how do i get the date/time of the web server hosting the website... i know the function Now() get the client side time.. but what if i wan the server-side time... please help...Have a look at this (http://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock)
but that is in javascript.. what if my page language is in vb???
can i find out whether there is any code which will display the GMT of the client.. ex: my gmt is +8 so when my computer request from the server it should display GMT+8...
DateTime.Now does not give client time. It will give you the server time.

To get the time zone of the client, you need to use javascript.

var d = new Date();
alert(d.getTimezoneOffset());
sorry when it come to prgramming for time i am quite a noob..u mind give me the full syntax for DateTime.Now ??
u mind give me the full syntax for DateTime.Now ??

DateTime.Now

Yes, that is the syntax. To display it, you can use

DateTime.Now.ToString()

or

DateTime.Now.ToShortDateTimeString()

and other available methods which should be visible to you in the intellisense.

web Service

how to call a function from wed services to a windows application?Please explain more about what you want to do. You want to write a Web service that makes a call to a Windows application? What kind of Windows application? What are you trying to do?

Don
donkienly thanks for your reply.Lets make my question more specific.If i would like to do a calculator which is in the windows application where the calculation metod/function are all in the web services.
problems is I already created the web services but i cant call it out from in the windows application,while i write the function name in the windows application it shown me the error that the function is not a member of the web services.how can i avoid it?
Ah, gotcha. Have you added a Web reference to your project, assuiming you are using Visual Studio .NET? If not, you have to do that first, in the Solution Explorer window.

Let me know if you've done that, and we can go from there.

Don
Refer
Link
thanks i managed to fixed it
how if i would like to store the data from the web service to the client database(PDA) where the client is programed in windows application.

Monday, March 26, 2012

Web Service as function return value

I want to be able to switch between a local test Web Service and a server
based live Web Service.
When testing numerous web forms I need to switch their Web Service reference between a local development service and the live one.
At the moment this involves replacing the declaration 'TestWebService' with 'LiveWebService' in each form.
What I would like to do is have a utilities class that has a static function
that returns a reference to the appropriate web service depending upon a key
in web.config.
I would be able to do this if I knew how to declare the return value of the
function:

internal static ???? GetWebService()
{
string lstrWebService =
ConfigurationSettings.AppSetting["WebService"].ToString();
if(lstrWebService == "Test")
{
return ????;
}
else
{
return ????;
}
}

Anyone know what the ???s should be or if what I want is not possible.What do you mean by returning a "a reference to the appropriate web service"? Can you show me an example?
What do you mean by returning a "a reference to the appropriate web service"? Can you show me an example?
I've got 2 Web Services referenced and I wanted to switch between them, but I now realise that this is totally the wrong way to do it!!!
I'm going to have only one service referenced and change its URL when necessary. All I need to do is ensure that the services maintain the same contracts.
A real blonde moment, or moments 'cos I've been doing it wrong for ages. :blush:
I was thinking along the same lines but your initial post confused me (with the Return values). The only thing that did require changing, as you've seen, was the .URL property...

Saturday, March 24, 2012

Web Service for Sql Connections

I want to have a function available to multiple apps that creates connections to our sql server 7 database (they do not want to upgrade to 2000 or 2005 yet). My questions are:

Is it safe to put functions that connect to the db in a web service?

Should I have any additional security measures in place?

Here is a sample of one I converted to be potentially used:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService
Public globConnection As SqlConnection
Public gstrDBName As String
Public gstrSwitchboardPath As String
Public gstrHelpPath As String

<WebMethod()> _

'This Module is the ONLY access to the SQL Server
'It is using NT Authentication to permit access
'If the user is not a Valid NT user access is Denied
'If the user has not been granted permission to the SQL server access will be Denied

Public Function ConnectToDB() As Boolean

Dim BoolState As Boolean
Dim strConnection As String

gstrDBName = "DBNAME"

strConnection = "Provider=SQLOLEDB.1;" & _
"Data Source= SERVERNAME;Initial Catalog= " & gstrDBName & ";" & _
"Integrated Security=SSPI "
On Error Resume Next

If globConnection Is Nothing Then
globConnection = New SqlConnection
End If

If globConnection.State = Data.ConnectionState.Open Then
BoolState = True
Else
globConnection = New SqlConnection
globConnection.ConnectionString = strConnection
globConnection.Open()
If globConnection.State = Data.ConnectionState.Open Then
BoolState = True
Else
BoolState = False
End If
End If
ConnectToDB = BoolState
End Function 'ConnectToDB

End Class

Any input, suggestions, etc would be greatly appreciated.its fine so long as the public methods you expose through your webservice don't open the door for someone to send in malicious code..

for example, if your webservice exposed a routine that allowed you to pass a SQL string to it and run that against your DB, that would be a bad risk, because someone could easily pass a string to delete all your tables.

You may also want to disallow public access to your service or have authentication of some sort for the users of the service.
We use all stored procedures, no hard coding SQL into any of our code. Our VB 6.0 security Model looks something like this currently:

Database
Stored Procedure
Class
Module
Application

I am trying to figure out how to implement similar security layers in ASP 2.0 and be able to use alot of the newer functionality, improve scalability (they want to roll this stuff out to multiple US and International - eventually - clients) without having to install cumbersome applications that require local support when users hose them up entirely or have to worry about how much memory, etc they have. Connectivity is not an issue because if they lose connectivity to us it does not matter what they use. I have been studying this article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/secnetch03.asp
If there are any other decent articles out there, can I get links to them?

Thank you very much.
hows about this one

http://msdn2.microsoft.com/en-us/library/w67h0dw7.aspx
Ok, I have security squared away...I think hehe. Now I run into a bigger problem - connecting a gridview to SQL Server 7.0. I know that it cannot be done directly and I have to use a dataset, however I cannot seem to figure out the right configuration of parameters and/or syntax to make it happen. Any help? Here is what I have so far that is not utterly ridiculous:

Public globConnection As SqlConnection
Public globDS As SqlDataSource

Public Function ConnectToDS() As SqlDataSource
Dim strConnection As String
gstrDBName = "DBNAME"

strConnection = "Provider=SQLOLEDB.1;" & _
"Data Source= ServerName;Initial Catalog= " & gstrDBName & ";" & _
"Integrated Security=SSPI "

If globConnection Is Nothing Then
globConnection = New SqlConnection
End If

globDS.ConnectionString = strConnection

ConnectToDS = globDS
End Function

I have been and continue to look on the web. The only thing I have found a reference to is caching...not alot of detail just reference. Again, any suggestions, pointers and guidance is muchly appreciated.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx

web service issue

hi all
I created a web service with one web method:
<WebMethod()> Public Function RequestPremium(ByVal web_request As
XmlDocument) As XmlDocument
it basically accepts a xmldocument then queries a database and returns
results in a xmldocument
I've confirmed that the code in the web method works, it fails when
the web method tries to return the new xmldocument:
last couple of lines in web method...
o_xmlreturn.Save("C:\temp\WS.xml") ' this works, xmldocument has
data and saves to the web server in c:temp
RequestPremium = o_xmlreturn ' this fails when it returns back to
calling program
my calling program is just a test windows vb.net app. the calling
lines are
ws_webservice = New WebService.POCservice ' web reference
ws_webservice.Credentials = New System.Net.NetworkCredential("user",
"pwd", "domain")
xml_return = ws_WIS_webservice.RequestPremium(xml_send)
error message in calling program is:
"system.invalidcastexception: specified cast is not valid"
can you return a xmldocument in a web service? I passed one and it
worked fine, just won't return it
any help would be appreciated. thanksIf I recall correctly, it will be happier returning an XmlNodeList or
XmlDocumentFragment. Try that.
Peter
--
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com
"esource" wrote:

> hi all
> I created a web service with one web method:
> <WebMethod()> Public Function RequestPremium(ByVal web_request As
> XmlDocument) As XmlDocument
> it basically accepts a xmldocument then queries a database and returns
> results in a xmldocument
> I've confirmed that the code in the web method works, it fails when
> the web method tries to return the new xmldocument:
> last couple of lines in web method...
> o_xmlreturn.Save("C:\temp\WS.xml") ' this works, xmldocument has
> data and saves to the web server in c:temp
> RequestPremium = o_xmlreturn ' this fails when it returns back to
> calling program
> my calling program is just a test windows vb.net app. the calling
> lines are
> ws_webservice = New WebService.POCservice ' web reference
> ws_webservice.Credentials = New System.Net.NetworkCredential("user",
> "pwd", "domain")
> xml_return = ws_WIS_webservice.RequestPremium(xml_send)
> error message in calling program is:
> "system.invalidcastexception: specified cast is not valid"
> can you return a xmldocument in a web service? I passed one and it
> worked fine, just won't return it
> any help would be appreciated. thanks
>
"esource" <darrenpaul@.shaw.ca> wrote in message
news:1186000686.219397.65420@.l70g2000hse.googlegroups.com...
> hi all
> I created a web service with one web method:
> <WebMethod()> Public Function RequestPremium(ByVal web_request As
> XmlDocument) As XmlDocument
> it basically accepts a xmldocument then queries a database and returns
> results in a xmldocument
> I've confirmed that the code in the web method works, it fails when
> the web method tries to return the new xmldocument:
> last couple of lines in web method...
> o_xmlreturn.Save("C:\temp\WS.xml") ' this works, xmldocument has
> data and saves to the web server in c:temp
> RequestPremium = o_xmlreturn ' this fails when it returns back to
> calling program
> my calling program is just a test windows vb.net app. the calling
> lines are
> ws_webservice = New WebService.POCservice ' web reference
> ws_webservice.Credentials = New System.Net.NetworkCredential("user",
> "pwd", "domain")
> xml_return = ws_WIS_webservice.RequestPremium(xml_send)
> error message in calling program is:
> "system.invalidcastexception: specified cast is not valid"
> can you return a xmldocument in a web service? I passed one and it
> worked fine, just won't return it
> any help would be appreciated. thanks
You say that the exception is in the calling code, yet you posted the code
of the service. Did you look at the calling code (that is, at the proxy
class)?
If you look at your proxy class (Reference.vb usually), you'll see that the
proxy method returns XmlNode, not XmlDocument.
--
John Saunders [MVP]
On Aug 1, 5:34 pm, "John Saunders [MVP]" <john.saunders at
trizetto.com> wrote:
> "esource" <darrenp...@.shaw.ca> wrote in message
> news:1186000686.219397.65420@.l70g2000hse.googlegroups.com...
>
>
>
>
>
>
>
> You say that the exception is in the calling code, yet you posted the code
> of the service. Did you look at the calling code (that is, at the proxy
> class)?
> If you look at your proxy class (Reference.vb usually), you'll see that th
e
> proxy method returns XmlNode, not XmlDocument.
> --
> John Saunders [MVP]- Hide quoted text -
> - Show quoted text -
thanks both of you.
Your right, I checked the web reference in my calling program in
reference.vb and the implementation was xmlnode even though I declared
it as xmldocument in my web service. I changed it and it worked.
thanks again