Creating .NET SOAP Clients in .NET framework

Creator Data Matrix ECC200 in .NET framework Creating .NET SOAP Clients

Creating .NET SOAP Clients
Data Matrix Reader In Visual Studio .NET
Using Barcode Control SDK for .NET Control to generate, create, read, scan barcode image in Visual Studio .NET applications.
Generating DataMatrix In VS .NET
Using Barcode generation for .NET framework Control to generate, create Data Matrix 2d barcode image in Visual Studio .NET applications.
Using the .NET Framework, this section demonstrates the creation of SOAP clients that access methods configured to return data via different methods and using the following formats: Return values and output parameters XML elements Array of data sets Single data set If you are planning to run the code examples, you will need to map the following functions to web service methods: Method
Scanning DataMatrix In .NET Framework
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
Barcode Generator In Visual Studio .NET
Using Barcode generator for Visual Studio .NET Control to generate, create barcode image in .NET framework applications.
OrderAdd fn_DepartmentEquipment
Barcode Decoder In Visual Studio .NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
Make Data Matrix In Visual C#
Using Barcode printer for Visual Studio .NET Control to generate, create DataMatrix image in .NET applications.
Stored Procedure
Generate Data Matrix ECC200 In .NET
Using Barcode printer for ASP.NET Control to generate, create ECC200 image in ASP.NET applications.
Creating Data Matrix 2d Barcode In Visual Basic .NET
Using Barcode printer for Visual Studio .NET Control to generate, create ECC200 image in VS .NET applications.
prOrder_Add fn_DepartmentEquipment
Painting EAN 128 In Visual Studio .NET
Using Barcode printer for .NET Control to generate, create EAN 128 image in Visual Studio .NET applications.
Encode Barcode In .NET Framework
Using Barcode creation for VS .NET Control to generate, create bar code image in Visual Studio .NET applications.
Output
Making Data Matrix ECC200 In VS .NET
Using Barcode maker for VS .NET Control to generate, create Data Matrix image in VS .NET applications.
Encoding Postnet 3 Of 5 In Visual Studio .NET
Using Barcode generator for .NET Control to generate, create Postnet 3 of 5 image in .NET applications.
XML elements XML elements
Generate Barcode In VB.NET
Using Barcode generation for .NET framework Control to generate, create bar code image in .NET applications.
Generate Linear Barcode In VB.NET
Using Barcode encoder for Visual Studio .NET Control to generate, create 1D Barcode image in .NET framework applications.
15: Modifying Databases Using SQLXML
Code 128A Encoder In None
Using Barcode maker for Font Control to generate, create Code 128 image in Font applications.
Create Code 128B In VB.NET
Using Barcode printer for VS .NET Control to generate, create Code-128 image in .NET applications.
Method
Draw GTIN - 128 In Java
Using Barcode generation for Java Control to generate, create EAN / UCC - 14 image in Java applications.
Scanning European Article Number 13 In VB.NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
prOrderItemByOrderId_List prOrderRequestedBy_List
Make ANSI/AIM Code 128 In VS .NET
Using Barcode printer for ASP.NET Control to generate, create ANSI/AIM Code 128 image in ASP.NET applications.
Generating GTIN - 13 In Java
Using Barcode encoder for Eclipse BIRT Control to generate, create EAN / UCC - 13 image in BIRT applications.
Stored Procedure
prOrderItemByOrderId_List prOrderRequestedBy_List
Output
Single data set Array of data sets
Adding a Web Service Reference in Visual Studio .NET Project
To create a SOAP client in Visual Studio .NET, you need to create a new project, and then add a reference to the XML Web Service using Project | Add Web Reference. The program opens the Add Web Reference browser window to allow you to connect to the UDDI directory of the web services (see Figure 15-7), or you can simply type the web address of the web service:
http://localhost/Asset/soap wsdl
The wsdl parameter of the URL compels the program to open the file containing the web service description.
Figure 15-7
The Add Web Reference browser window
SQL Server 2000 Stored Procedure & XML Programming
The program opens the WSDL file and displays it on the screen. You can browse it or simply click Add Reference and the program adds it to your solution as a web reference. The web reference is named after the server that hosts the web service (localhost in this case). Use this opportunity to give it a more meaningful name (see Figure 15-8). Based on information found in the WSDL file, Visual Studio .NET generates a proxy class in your project, which you can use to access web service methods.
NOTE
The proxy class does not allow non-string output parameters to get null values from XML Web Services. If your service returns nulls, you can either assign it to string values or rewrite the proxy class to accept nulls.
If you ever make a change to the web service, you can refresh the web reference and the class it creates: open Solution Explorer, open Web References, right-click the service name (in the example, localhost, or AssetOrderService), and select Update Web Reference from the context menu.
Simple .NET Client
I will start with a client that simply makes a request from the web service and retrieves an output parameter. The client uses the OrderAdd method mapped to the
Figure 15-8
A web reference in Visual Studio .NET Solution Explorer
15: Modifying Databases Using SQLXML
prOrder_Add stored procedure. It accepts several parameters and returns the OrderId that was assigned to the order during the insert.
alter procedure prOrder_Add -- insert Order and return Order id -- used in soap demonstration @OrderDate smalldatetime, @RequestedById int, @TargetDate smalldatetime, @DestinationLocationId int, @Note varchar(200), @OrderTypeId smallint, @OrderStatusid tinyint, @OrderId int output as declare @intErrorCode int INSERT INTO [Order]([OrderDate], [RequestedById], [TargetDate], [DestinationLocationId], [Note], [OrderTypeId], [OrderStatusid]) VALUES(@OrderDate, @RequestedById, @TargetDate, @DestinationLocationId, @Note, @OrderTypeId, @OrderStatusid) select @OrderId = scope_identity(), @intErrorCode = @@Error return @intErrorCode
The following Visual Basic .NET console application instantiates a web service proxy object (objWSProxy) based on the class that was generated using WSDL. The application needs to set the Credentials property of the proxy object when a web service does not accept anonymous users. Finally, the method of the web service is executed through the proxy method of the proxy object. As an application developer, you do not have to worry about the intricacies of the SOAP protocol. The proxy object takes care of it.
'SqlXml_SoapSimple Imports System Imports System.IO Module Module1 Sub Main() Dim objResponse As Object() Dim iOrderId As Integer
SQL Server 2000 Stored Procedure & XML Programming
Dim objWSProxy As New AssetOrdersService.AssetOrders() objWSProxy.Credentials = System.Net.CredentialCache.DefaultCredentials objResponse = objWSProxy.OrderAdd("3/3", 1, "5/5", 1, _ "URGENT!", 1, 1, _ iOrderId) Console.WriteLine("OrderID: " & iOrderId) End Sub End Module
Function That Returns Data Sets as XML Elements
The next project uses a table-valued, user-defined function mapped to the method that returns output as XML elements:
'SqlXml_Soap_XmlElements Imports System Imports System.IO Module Module1 Sub Main() Dim objResponse As Object() Dim objError As Object Dim iElem As Integer Dim objResponseElement As System.Xml.XmlElement Dim objWSProxy As New AssetOrdersService.AssetOrders() objWSProxy.Credentials = System.Net.CredentialCache.DefaultCredentials objResponse = objWSProxy.fn_DepartmentEquipment("dejans") For iElem = 0 To objResponse.GetUpperBound(0) Select Case objResponse(iElem).GetType().ToString() Case "System.Xml.XmlElement" objResponseElement = objResponse(iElem) Console.WriteLine(objResponseElement.OuterXml) Case "SqlMessage" objError = objResponse(iElem) Console.WriteLine(objError.Message) Console.WriteLine(objError.Source) End Select
Copyright © OnBarcode.com . All rights reserved.