|
-
Jan 6th, 2011, 05:14 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Web Service Assure Delivery
Hello
I have two web services on two different servers communicating
WS1.asmx
Code:
<%@ WebService Language="VB" Class="WS1" %>
Imports System
Imports System.Web
Imports System.Web.Services
Imports System.Xml.Serialization
Imports System.Net
Imports System.IO
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://www.test.com/ws")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class WS1
Inherits System.Web.Services.WebService
Dim IP as String = "192.168.0.174"
<WebMethod()> _
Public Function Function1(ByVal s1 As String) As String
Dim ReturnString As String = ""
Try
Dim soap As String = "<?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><Function2 xmlns=""http://www.test.com/ws""><s2>" & s1 & "</s2></Function2></soap:Body></soap:Envelope>"
Dim req As HttpWebRequest = WebRequest.Create("http://" & IP & "/WS2.asmx")
req.Headers.Add("SOAPAction", "http://www.test.com/ws/Function2")
req.ContentType = "text/xml;charset=\utf-8\"
req.Accept = "text/xml"
req.Method = "POST"
Using stm As Stream = req.GetRequestStream()
Using stmw As New StreamWriter(stm)
stmw.Write(soap)
End Using
End Using
Dim response As WebResponse = req.GetResponse()
Dim responseStream As Stream = response.GetResponseStream()
Dim s_read As New System.IO.StreamReader(responseStream)
ReturnString = s_read.ReadToEnd
s_read.Close()
ReturnString = Replace(ReturnString, "<?xml version=""1.0"" encoding=""utf-8""?><soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""><soap:Body><Function2Response xmlns=""http://www.test.com/ws""><Function2Result>", "")
ReturnString = Replace(ReturnString, "</Function2Result></Function2Response></soap:Body></soap:Envelope>", "")
Catch ex As Exception
ReturnString = ex.Message
End Try
Return ReturnString
End Function
End Class
WS2.asmx
Code:
<%@ WebService Language="VB" Class="WS2" %>
Imports System
Imports System.Web
Imports System.Web.Services
Imports System.Xml.Serialization
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://www.test.com/ws")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class WS2
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function Function2(ByVal s2 As String) As String
Dim ReturnString As String = ""
Try
ReturnString = "Hello " & s2
Catch ex As Exception
ReturnString = ex.Message
End Try
Return ReturnString
End Function
End Class
WS1 calls a function in WS2, my problems is what if the communication between the two servers goes down, is there any way to keep re-trying for a certain time out period (2 minutes suppose) ??
Thank you
-
Jan 6th, 2011, 07:36 AM
#2
Re: Web Service Assure Delivery
Hello,
By default, Web Services, and Web Service Methods should be stateless. If an error occurs in the second webservice, then it should either be handled by the calling web service, or the caller of the first web service should be notified.
How is the first service to know that it is a connection issue, and keep trying, rather than an actual exception?
Gary
-
Jan 6th, 2011, 07:41 AM
#3
Thread Starter
Addicted Member
Re: Web Service Assure Delivery
Well with connection problems you get a "URL not found" exception, and the max you can do with that is try for one more time only
The one thing I can think of is trying to simply ping the remote server before actually calling the function.. am not sure if that sounds logical !!
-
Jan 6th, 2011, 07:52 AM
#4
Re: Web Service Assure Delivery
Hello,
The point that I was trying to make is that you should return that exception to the caller of the first webservice. If they want to try again, then they can.
The alternatives would be, as you suggested.
1) First "ping" the server to see if it is available. Rather than "ping" I would add another web method to your second Web Service called CheckStatus, and return "good" if it can be called.
2) Using a Timer, continue to loop for a set period of time, checking for the exception, and continue to call the method on the second web service.
However, all of the above apply also for the first web service, as communication to it might also go down.
Why do you need to chain the Web Services? Can you not combine them?
Gary
-
Jan 6th, 2011, 07:56 AM
#5
Thread Starter
Addicted Member
Re: Web Service Assure Delivery
Timers work with web services !!? I had no idea am gonna give it a try
Well am a building a middleware that routes requests to different branches.. so WS1 is my central platform and WS2 will be duplicated on several servers with several IP addresses
U know of a better scenario that does this ??
-
Jan 6th, 2011, 08:32 AM
#6
Re: Web Service Assure Delivery
Yes, timers "can" be used, but I tend to shy away from the use of them. As I mentioned, Web Services should be stateless, and the use of timers, to me, apply state.
How about letting the request talk directly to the second web service. The application could first make a call to WS1 saying, "Who should I talk to?". WS1 replys with the name of the server that the request should talk to, and from there, the application talks directly to WS2.
Without knowing the in's and out's of your application, it is difficult to say whether this approach will work. For instance, you might not want the application to talk directly to WS2.
Gary
-
Jan 7th, 2011, 04:24 AM
#7
Thread Starter
Addicted Member
Re: Web Service Assure Delivery
Well no I don't want that
Now since there is no straight forward solution for this I was wondering about the use of Message Queues!!
Any idea about that ?? Delivering data to a queue and having a listener at the branch level to pick it up !?
-
Jan 7th, 2011, 07:57 AM
#8
Re: Web Service Assure Delivery
Hey,
Yip, Message Queues is a perfectly viable way of communicating across servers. Are these servers on the same network?
Gary
-
Jan 7th, 2011, 08:00 AM
#9
Thread Starter
Addicted Member
Re: Web Service Assure Delivery
Yes connected through VPN
-
Jan 7th, 2011, 08:03 AM
#10
Re: Web Service Assure Delivery
In which case, I don't see a reason to not use Message Queues. It is a very reliable way to communicate messages between different places.
Gary
-
Jan 7th, 2011, 08:07 AM
#11
Thread Starter
Addicted Member
Re: Web Service Assure Delivery
Thank you
-
Jan 7th, 2011, 08:48 AM
#12
Re: [RESOLVED] Web Service Assure Delivery
Not a problem at all.
Will be interesting to hear how you get on.
Gary
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
|