Purpose of webservice: this webservice will be invoked by a third party website (say abc.com). User will add a message in a webpage of abc.com this message will be sent to the Webservice.
Below mentioned is the code that I have written for a web service to store the parameters/message sent by third party application.
-- Service1.asmx page
Expand|Select|Wrap|Line Numbers
- Imports System.Web.Services
- Imports System.Web
- Imports System.Data.SqlClient
- Imports System.Collections.Specialized
- Imports System.Web.Services.Protocols
- <System.Web.Services.WebService(Namespace:="http://www.MyWebsiteAddress.com/Converter/Service1")> _
- Public Class Service1
- Inherits System.Web.Services.WebService
- ' WEB SERVICE EXAMPLE
- ' The HelloWorld() example service returns the string Hello World.
- ' To build, uncomment the following lines then save and build the project.
- ' To test this web service, ensure that the .asmx file is the start page
- ' and press F5.
- <WebMethod()> _
- Public Sub ProcessRequest(ByVal userKey As String, ByVal message As String, ByVal listen As String) // Mentioned here are the parameters will be sent to this web service
- Dim strcon As String
- strcon = "server=ip; database=dbname; uid=XXX; pwd=XXX"
- Dim objConn As New SqlConnection(strcon)
- Dim objTrans As SqlTransaction
- objConn.Open()
- objTrans = objConn.BeginTransaction
- Dim strSQL As String = ""
- strSQL = "insert into TableName (UserKey,Message,Voicelink)values"
- strSQL = strSQL + "('" & userKey & "','" & message & "','" & listen & "')"
- Dim cmd As New SqlCommand(strSQL, objConn)
- cmd.Transaction = objTrans
- cmd.CommandType = Data.CommandType.Text
- cmd.ExecuteNonQuery()
- objTrans.Commit()
- End Sub
- End Class
After doing this process i tested the webservice by http://MyWebsiteName.com/Service1.asmx and recived error "The test form is only available for requests from the local machine.".. To resolve this error I added below mentioned code in the web.cong file of application not in the web.config of Webservice.
Expand|Select|Wrap|Line Numbers
- <webServices>
- <protocols>
- <add name="HttpGet"/>
- <add name="HttpPost"/>
- </protocols>
- </webServices>
Now the third party application has asked to enter the link of webservice which will receive the hit when user add the message, so I have given it as http://MyWebsiteName.com/Service1.asmx.
But when I try to send the message from third party application as a part of testing in a real envoirenment I should get a hit to the above mentioned URL (Web Service), But, I'm not getting a hit(Data is not saved into the database).
So, I think, either my web service is not deployed properly (the porcess I have done of coping the files and .DLL to the development server is not sufficent to get the hit from third party) or the code written in SUB ProcessRequest is not able to recieve the query string parameters from the thrid party application.
Please note that I'm creating the web service in Microsoft Visual Studio .NET 2003 using VB.net
Please help its urgent.
Thanks,
Swapnil