WSDL: Command Line Tool

Objective
  • Create Services and consume Web-Services using command prompt.
  • disclaimer :dreamland is an intranet server 2003 for testing visual studio, PHP and others.
1. Create webservice: code

<%@ WebService Language="C#" Class="DisplayString" %>
using System.Web.Services;
[WebService(Namespace="http://dreamland/soap/Ch19/")]
public class DisplayString
{
[WebMethod(Description="Returns a String value")]
public string GetString()
{
return "This Web Service Says hello!";
}
}
 
Step 2: 2. A proxy class does the hard work. It sends your method calls to a webservice and receives the SOAP encoded WSDL response. The wsdl command line tool WSDL.EXE generates the source for the proxy class.

Picture:   wsdl /l:cs http://dreamland/soap/Ch19/firstWebService.asmx?wsdl /o:firstWebServiceProxy.cs

 

3. Codes in csharp files.

//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.0.2914.16
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------

//
// This source code was auto-generated by wsdl, Version=1.0.2914.16.
//
namespace soap.Ch19 {
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.Web.Services;


[System.Web.Services.WebServiceBindingAttribute(Name="DisplayStringSoap", Namespace="soap/Ch19")]
public class DisplayString : System.Web.Services.Protocols.SoapHttpClientProtocol {

[System.Diagnostics.DebuggerStepThroughAttribute()]
public DisplayString() {
this.Url = "http://dreamland/soap/Ch19/firstWebService.asmx";
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("soap/Ch19/GetString", RequestNamespace="soap/Ch19", ResponseNamespace="soap/Ch19", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string GetString() {
object[] results = this.Invoke("GetString", new object[0]);
return ((string)(results[0]));
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
public System.IAsyncResult BeginGetString(System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetString", new object[0], callback, asyncState);
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
public string EndGetString(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string)(results[0]));
}
}
}
 
  1. If you click on Service description.

<?xml version="1.0" encoding="utf-8" ?>
- <definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s0="http://dreamland/soap/Ch19/" targetNamespace="http://dreamland/soap/Ch19/" xmlns="http://schemas.xmlsoap.org/wsdl/">
- <types>
- <s:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://dreamland/soap/Ch19/">
- <s:element name="GetString">
<s:complexType />
</s:element>
- <s:element name="GetStringResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="GetStringResult" nillable="true" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="string" nillable="true" type="s:string" />
</s:schema>
</types>
- <message name="GetStringSoapIn">
<part name="parameters" element="s0:GetString" />
</message>
- <message name="GetStringSoapOut">
<part name="parameters" element="s0:GetStringResponse" />
</message>
<message name="GetStringHttpGetIn" />
- <message name="GetStringHttpGetOut">
<part name="Body" element="s0:string" />
</message>
<message name="GetStringHttpPostIn" />
- <message name="GetStringHttpPostOut">
<part name="Body" element="s0:string" />
</message>
- <portType name="DisplayStringSoap">
- <operation name="GetString">
<documentation>Returns a String value</documentation>
<input message="s0:GetStringSoapIn" />
<output message="s0:GetStringSoapOut" />
</operation>
</portType>
- <portType name="DisplayStringHttpGet">
- <operation name="GetString">
<documentation>Returns a String value</documentation>
<input message="s0:GetStringHttpGetIn" />
<output message="s0:GetStringHttpGetOut" />
</operation>
</portType>
- <portType name="DisplayStringHttpPost">
- <operation name="GetString">
<documentation>Returns a String value</documentation>
<input message="s0:GetStringHttpPostIn" />
<output message="s0:GetStringHttpPostOut" />
</operation>
</portType>
- <binding name="DisplayStringSoap" type="s0:DisplayStringSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <operation name="GetString">
<soap:operation soapAction="http://dreamland/soap/Ch19/GetString" style="document" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
</binding>
- <binding name="DisplayStringHttpGet" type="s0:DisplayStringHttpGet">
<http:binding verb="GET" />
- <operation name="GetString">
<http:operation location="/GetString" />
- <input>
<http:urlEncoded />
</input>
- <output>
<mime:mimeXml part="Body" />
</output>
</operation>
</binding>
- <binding name="DisplayStringHttpPost" type="s0:DisplayStringHttpPost">
<http:binding verb="POST" />
- <operation name="GetString">
<http:operation location="/GetString" />
- <input>
<mime:content type="application/x-www-form-urlencoded" />
</input>
- <output>
<mime:mimeXml part="Body" />
</output>
</operation>
</binding>
- <service name="DisplayString">
- <port name="DisplayStringSoap" binding="s0:DisplayStringSoap">
<soap:address location="http://dreamland/soap/Ch19/firstWebService.asmx" />
</port>
- <port name="DisplayStringHttpGet" binding="s0:DisplayStringHttpGet">
<http:address location="http://dreamland/soap/Ch19/firstWebService.asmx" />
</port>
- <port name="DisplayStringHttpPost" binding="s0:DisplayStringHttpPost">
<http:address location="http://dreamland/soap/Ch19/firstWebService.asmx" />
</port>
</service>
</definitions>
 

Consume webservices
The proxy cs file you just created can be consumed with an aspx client. If we code

<%@ Assembly Src="firstWebServiceProxy.cs"%>
<html>
<head>
<script language="C#" runat="server">
void Page_Load(Object Sender, EventArgs E)
{
DisplayString message = new DisplayString();
Response.Write("The GetString method of firstWebService returns: " + message.GetString());
}
</script></head><body>
</body>
</html>

 

The class could not be recognized by the client, unless we define with namespace

 The correct code is as follows.
<%@ Assembly Src="firstWebServiceProxy.cs"%>
<html>
<head>
<script language="C#" runat="server">
void Page_Load(Object Sender, EventArgs E)
{
soap.Ch19.DisplayString message = new soap.Ch19.DisplayString();
Response.Write("The GetString method of firstWebService returns: " + message.GetString());
}
</script></head><body>
</body>
</html>