Found this article and bookmarking here.
http://alteksolutions.com/wp/index.php/2009/03/quick-and-dirty-guide-to-creating-qaaws/
Showing posts with label web service. Show all posts
Showing posts with label web service. Show all posts
Wednesday, October 27, 2010
Friday, October 31, 2008
Consuming Webservice using MSSoap
Even though majority of the programmers have started using vb.net, there may be cases where you have a legacy system that still needs to consume webservice. This is how to do it with MSSoap.
First thing to be aware of is you may encounter issue if the webservice returns XML, so have it return a string instead. This is easily done by using a wrapper function. For example, if you have a webmethod say getLotData, just create a getLotDataStr as follows:
E.g.
First thing to be aware of is you may encounter issue if the webservice returns XML, so have it return a string instead. This is easily done by using a wrapper function. For example, if you have a webmethod say getLotData, just create a getLotDataStr as follows:
To consume the webservice, in vbscript or VB, you then use the MSSoap client as follows:
<WebMethod()> _
Public Function getLotData(ByVal pLotID As String) As XmlDocument
....
End Function
...
<WebMethod()>
Public Function getLotDataStr(ByVal pLotID As String) As String
Dim tmpStr As String = ""
Dim xDoc As XmlDocument
xDoc = getLotData(pLotID)
tmpStr = xDoc.OuterXml
Return tmpStr
End Function
Once the information is loaded to the XmlDocument, you can then access the information by using the getElementsByTagName. You can also access the inner text by access the Text Property.
Dim wsClient As New MSSOAPLib30.SoapClient30
Dim urlStr as String = "http://www.blogger.com/wservice.asmx?WSDL"
Dim sReply, lotID As String
Dim xDoc As DOMDocument30
lotID = ...
wsClient.MSSoapInit urlStr
sReply = wsClient.getLotDataStr(lotID)
xDoc.loadXML sReply
...
E.g.
You can also use the DomDocument30 data type to create the parameters if the Webservice requires a XML as a parameter.
Dim lotNode As IXMLDOMNode
Dim processStep As String
Set lotNode = xDoc.getElementByTagName("processID")
ProcessStep = lotNode.Text
'If it is an attribute then access it by the Attributes as in
ProcessStep = lotNode.Attributes.getNameItem("Name").Text
Wednesday, October 22, 2008
Consuming WebService in Lotus NOTES
I found it difficult to find reference on how to consume webservice in Lotus NOTES. That is why I have this as a bookmark to help me get back to those locations:
Consuming webservice in LN 6
Another good one that shows a simple client side method is found here (snippet as follows):
There is also an open source project which produces a java stub to consume the webservice called stubby, however, still not sure whether is meets my counterparts requirements.
In LN 8, it is much simpler to consume the webservice, just have to create a new script - either JavaScript, LotusScript or Java Library and there is a button at the bottom labeled WSDL, just click it and import WSDL to create the required reference to consume the webservice.
There is also another reference on how to write do some of the coding in java - found here. Another reference talking about webservice in LN 8.5 is found here.
Consuming webservice in LN 6
Another good one that shows a simple client side method is found here (snippet as follows):
Dim Client As Variant
Set Client = CreateObject("MSSOAP.SoapClient")
'Initialize connection to the Web Service
Call Client.mssoapinit
("http://localhost/testWS.nsf/Simple?wsdl")
'Call our simple GetEmailAddress
function provided by Web service
Dim result As String
result = Client.getJoke()
'output result to message box
Messagebox result, 48, "Get Joke"
There is also an open source project which produces a java stub to consume the webservice called stubby, however, still not sure whether is meets my counterparts requirements.
In LN 8, it is much simpler to consume the webservice, just have to create a new script - either JavaScript, LotusScript or Java Library and there is a button at the bottom labeled WSDL, just click it and import WSDL to create the required reference to consume the webservice.
There is also another reference on how to write do some of the coding in java - found here. Another reference talking about webservice in LN 8.5 is found here.
Sunday, September 21, 2008
Invalid Path when consuming Webservice
This will happen if you are consuming a webservice which generates xml as return value. What happens is when the webservice works correctly, it will return a well formed xml as a reply.
However, if you are using IIS to serve the webservice and when there is an error, IIS will return the error in HTML. Since the routine (proxy class) that consumes the webservice expects a well formed xml and it gets a html response (which is typically an invalid xml), it will return "Invalid Path".
Unfortunately, in most cases the error is very misleading.
However, if you are using IIS to serve the webservice and when there is an error, IIS will return the error in HTML. Since the routine (proxy class) that consumes the webservice expects a well formed xml and it gets a html response (which is typically an invalid xml), it will return "Invalid Path".
Unfortunately, in most cases the error is very misleading.
Saturday, July 19, 2008
Flexible consumption of Webservice
A quick way to consume a web service is to add Web Reference to the project. This works well most of the time.
However, imagine a scenario where you are supporting multiple sites in different countries and assuming that each of these sites are hosting the similar webservice locally. If you were to use web reference then you will need to compile a copy for each of theses sites (after changing the reference).
A much better way is to:
"c:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\wsdl.exe" /o:samplews.vb /l:vb /n:MyService http://localhost/sampleSrv/Service1.asmx?wsdl
Depending on which version of VS you have, the wsdl.exe may be in a different folder. For VS 2008, it is in c:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\wsdl.exe
In the above example, my webservice is http://localhost/sampleSrv/Service1.asmx and I created a proxy program in VB (Visual Basic) and saved it in a file samplews.vb. I also indicated that the class be placed with a namespace MyService.
The following is a snippet of the code generated:
Make a copy of the new subroutine and change it as follows:
Either add this new source code to your project or create it as an independent assembly (dll) and reference it.
To use it then, you create:
Dim vSvc as New MyService.Service1(url)
' Where url is a string variable which you get the value from your application config file.
instead of
Dim vSvc As New MyService.Service1()
However, imagine a scenario where you are supporting multiple sites in different countries and assuming that each of these sites are hosting the similar webservice locally. If you were to use web reference then you will need to compile a copy for each of theses sites (after changing the reference).
A much better way is to:
- Create a proxy class using the wsdl.exe tool from Microsoft.
- Copy the constructor from the proxy class and create one that will take the url as a parameter.
- Use this new constructor in the project that needs to consume the webservice and refer to the config file for the url (so you just need to change that value for each site).
"c:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\wsdl.exe" /o:samplews.vb /l:vb /n:MyService http://localhost/sampleSrv/Service1.asmx?wsdl
Depending on which version of VS you have, the wsdl.exe may be in a different folder. For VS 2008, it is in c:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\wsdl.exe
In the above example, my webservice is http://localhost/sampleSrv/Service1.asmx and I created a proxy program in VB (Visual Basic) and saved it in a file samplews.vb. I also indicated that the class be placed with a namespace MyService.
The following is a snippet of the code generated:
'------------------------------------------------------------------------------
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.1.4322.2407
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------
Option Strict Off
Option Explicit On
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
'
'This source code was auto-generated by wsdl, Version=1.1.4322.2407.
'
Namespace MyService
'<remarks/>
<System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Web.Services.WebServiceBindingAttribute(Name:="WriterServicesSoap", [Namespace]:="http://tempuri.org/")> _
Public Class Service1
Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
'<remarks/>
Public Sub New()
MyBase.New
Me.Url = "http://localhost/sampleSrv/Service1.asmx"
End Sub
Make a copy of the new subroutine and change it as follows:
Public Sub New(byval pUrl As String)
MyBase.New
Me.Url = pUrl
End Sub
Either add this new source code to your project or create it as an independent assembly (dll) and reference it.
To use it then, you create:
Dim vSvc as New MyService.Service1(url)
' Where url is a string variable which you get the value from your application config file.
instead of
Dim vSvc As New MyService.Service1()
Labels:
.Net,
Tips,
vb.net,
web service
Subscribe to:
Posts (Atom)