Default W SDL Help Generator
Default W SDL Help Generator
//
// DefaultWsdlHelpGenerator.aspx:
//
// Author:
// Lluis Sanchez Gual ([email protected])
//
// (C) 2003 Ximian, Inc. http://www.ximian.com
//
--%>
<html>
<script language="C#" runat="server">
ServiceDescriptionCollection descriptions;
XmlSchemas schemas;
string WebServiceName;
string WebServiceDescription;
string PageName;
string DefaultBinding;
ArrayList ServiceProtocols;
string CurrentOperationName;
string CurrentOperationBinding;
string OperationDocumentation;
string CurrentOperationFormat;
bool CurrentOperationSupportsTest;
ArrayList InParams;
ArrayList OutParams;
string CurrentOperationProtocols;
int CodeTextColumns = 95;
BasicProfileViolationCollection ProfileViolations;
void Page_Load(object sender, EventArgs e)
{
descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
schemas = (XmlSchemas) Context.Items["schemas"];
DefaultBinding = desc.Bindings[0].Name;
WebServiceDescription = service.Documentation;
if (WebServiceDescription == "" || WebServiceDescription == null)
WebServiceDescription = "Description has not been provided";
ServiceProtocols = FindServiceProtocols (null);
CurrentOperationName = Request.QueryString["op"];
CurrentOperationBinding = Request.QueryString["bnd"];
if (CurrentOperationName != null) BuildOperationInfo ();
BindingsRepeater.DataSource = list;
Page.DataBind();
void BuildOperationInfo ()
{
InParams = new ArrayList ();
OutParams = new ArrayList ();
OperationDocumentation = oper.Documentation;
if (OperationDocumentation == null || OperationDocumentation == "")
OperationDocumentation = "No additional remarks";
foreach (OperationMessage opm in oper.Messages)
{
if (opm is OperationInput)
BuildParameters (InParams, opm);
else if (opm is OperationOutput)
BuildParameters (OutParams, opm);
}
// Operation format
OperationBinding obin = FindOperation (binding, CurrentOperationName);
if (obin != null)
CurrentOperationFormat = GetOperationFormat (obin);
InputParamsRepeater.DataSource = InParams;
InputFormParamsRepeater.DataSource = InParams;
OutputParamsRepeater.DataSource = OutParams;
}
if (ob is XmlSchemaElement)
{
XmlSchemaElement selem = GetRefElement
((XmlSchemaElement)ob);
p.Name = selem.Name;
p.Type = selem.SchemaTypeName.Name;
}
else
{
p.Name = "Unknown";
p.Type = "Unknown";
}
list.Add (p);
}
}
else
{
foreach (MessagePart part in msg.Parts)
{
Parameter p = new Parameter ();
p.Description = "No additional remarks";
p.Name = part.Name;
if (part.Element == XmlQualifiedName.Empty)
p.Type = part.Type.Name;
else
{
XmlSchemaElement elem = (XmlSchemaElement) schemas.Find
(part.Element, typeof(XmlSchemaElement));
p.Type = elem.SchemaTypeName.Name;
}
list.Add (p);
}
}
}
return null;
}
return null;
}
bool HasFormResult
{
get { return Request.QueryString ["ext"] == "testform"; }
}
string GetOrPost ()
{
return (CurrentOperationProtocols.IndexOf ("HttpGet") >= 0) ? "GET" : "POST";
}
string GetQS ()
{
bool fill = false;
string qs = "";
NameValueCollection query_string = Request.QueryString;
for (int n = 0; n < query_string.Count; n++) {
if (fill) {
if (qs != "") qs += "&";
qs += query_string.GetKey(n) + "=" + Server.UrlEncode
(query_string [n]);
}
if (query_string.GetKey(n) == "ext") fill = true;
}
return qs;
}
string GetTestResultUrl ()
{
if (!HasFormResult) return "";
if (location == null)
return "Could not locate web service";
Port port;
if (protocol != "Soap") port = FindPort (null, protocol);
else port = FindPort (CurrentOperationBinding, null);
//
// Proxy code generation
//
string GetProxyCode ()
{
CodeNamespace codeNamespace = new CodeNamespace();
CodeCompileUnit codeUnit = new CodeCompileUnit();
codeUnit.Namespaces.Add (codeNamespace);
importer.Import(codeNamespace, codeUnit);
//
// Document generation
//
string GenerateDocument ()
{
StringWriter sw = new StringWriter ();
if (CurrentDocType == "wsdl")
descriptions [CurrentDocInd].Write (sw);
else if (CurrentDocType == "schema")
schemas [CurrentDocInd].Write (sw);
//
// Pages and tabs
//
string CurrentTab
{
get { return Request.QueryString["tab"] != null ?
Request.QueryString["tab"] : "main" ; }
}
string CurrentPage
{
get { return Request.QueryString["page"] != null ?
Request.QueryString["page"] : "main" ; }
}
void WriteTabs ()
{
if (CurrentOperationName != null)
{
WriteTab ("main","Overview");
WriteTab ("test","Test Form");
WriteTab ("msg","Message Layout");
}
}
class Tab
{
public string Id;
public string Label;
}
//
// Syntax coloring
//
return text;
}
//
// Helper methods and classes
//
string GetDataContext ()
{
return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding +
"&";
}
if (lastc==',' || lastc=='(')
{
if (!inquotes) breakpos = n;
}
lincount++;
lastc = c;
}
return sb.ToString ();
}
class Parameter
{
string name;
string type;
string description;
class EncodedType
{
public EncodedType (string ns, XmlSchemaElement elem) { Namespace
= ns; Element = elem; }
public string Namespace;
public XmlSchemaElement Element;
}
switch (protocol) {
case "Soap": return GenerateHttpSoapMessage (port, obin,
oper, msg);
case "HttpGet": return GenerateHttpGetMessage (port, obin,
oper, msg);
case "HttpPost": return GenerateHttpPostMessage (port,
obin, oper, msg);
}
return "Unknown protocol";
}
if (msg is OperationInput)
{
SoapAddressBinding sab = port.Extensions.Find
(typeof(SoapAddressBinding)) as SoapAddressBinding;
SoapOperationBinding sob = obin.Extensions.Find
(typeof(SoapOperationBinding)) as SoapOperationBinding;
req += "POST " + new Uri (sab.Location).AbsolutePath + "\
n";
req += "SOAPAction: " + sob.SoapAction + "\n";
req += "Content-Type: text/xml; charset=utf-8\n";
req += "Content-Length: " + GetLiteral ("string") + "\n";
req += "Host: " + GetLiteral ("string") + "\n\n";
}
else
{
req += "HTTP/1.0 200 OK\n";
req += "Content-Type: text/xml; charset=utf-8\n";
req += "Content-Length: " + GetLiteral ("string") + "\n\n";
}
if (msg is OperationInput)
{
HttpAddressBinding sab = port.Extensions.Find
(typeof(HttpAddressBinding)) as HttpAddressBinding;
HttpOperationBinding sob = obin.Extensions.Find
(typeof(HttpOperationBinding)) as HttpOperationBinding;
string location = new Uri (sab.Location).AbsolutePath +
sob.Location + "?" + BuildQueryString (msg);
req += "GET " + location + "\n";
req += "Host: " + GetLiteral ("string");
}
else
{
req += "HTTP/1.0 200 OK\n";
req += "Content-Type: text/xml; charset=utf-8\n";
req += "Content-Length: " + GetLiteral ("string") + "\n\n";
return req;
}
if (msg is OperationInput)
{
HttpAddressBinding sab = port.Extensions.Find
(typeof(HttpAddressBinding)) as HttpAddressBinding;
HttpOperationBinding sob = obin.Extensions.Find
(typeof(HttpOperationBinding)) as HttpOperationBinding;
string location = new Uri (sab.Location).AbsolutePath +
sob.Location;
req += "POST " + location + "\n";
req += "Content-Type: application/x-www-form-urlencoded\n";
req += "Content-Length: " + GetLiteral ("string") + "\n";
req += "Host: " + GetLiteral ("string") + "\n\n";
req += BuildQueryString (msg);
}
else return GenerateHttpGetMessage (port, obin, oper, msg);
return req;
}
xtw.WriteStartDocument ();
xtw.WriteStartElement ("soap", "Envelope",
SoapEnvelopeNamespace);
xtw.WriteAttributeString ("xmlns", "xsi", null,
XmlSchema.InstanceNamespace);
xtw.WriteAttributeString ("xmlns", "xsd", null,
XmlSchema.Namespace);
if (bodyUse == SoapBindingUse.Encoded)
{
xtw.WriteAttributeString ("xmlns", "soapenc", null,
SoapEncodingNamespace);
xtw.WriteAttributeString ("xmlns", "tns", null,
msg.Message.Namespace);
}
// Serialize headers
if (!writtenHeader) {
xtw.WriteStartElement ("soap", "Header",
SoapEnvelopeNamespace);
writtenHeader = true;
}
if (writtenHeader)
xtw.WriteEndElement ();
// Serialize body
xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
currentUse = bodyUse;
WriteBody (xtw, oper, msg, sbb, style);
xtw.WriteEndElement ();
xtw.WriteEndElement ();
xtw.Close ();
return sw.ToString ();
}
currentUse = header.Use;
if (currentUse == SoapBindingUse.Literal)
WriteRootElementSample (xtw, part.Element);
else
WriteTypeSample (xtw, part.Type);
}
if (style == SoapBindingStyle.Rpc) {
xtw.WriteStartElement (elemName, sbb.Namespace);
ns = sbb.Namespace;
}
if (!elem.RefName.IsEmpty) {
XmlSchemaElement refElem = FindRefElement (elem);
if (refElem == null) throw new InvalidOperationException
("Global element not found: " + elem.RefName);
root = elem.RefName;
elem = refElem;
sharedAnnType = true;
}
else
root = new XmlQualifiedName (elem.Name, ns);
if (!elem.SchemaTypeName.IsEmpty)
{
XmlSchemaComplexType st = FindComplexTyype
(elem.SchemaTypeName);
if (st != null)
WriteComplexTypeSample (xtw, st, root);
else
{
xtw.WriteStartElement (root.Name, root.Namespace);
if (currentUse == SoapBindingUse.Encoded)
xtw.WriteAttributeString ("type",
XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
xtw.WriteString (GetLiteral (FindBuiltInType
(elem.SchemaTypeName)));
xtw.WriteEndElement ();
}
}
else if (elem.SchemaType == null)
{
xtw.WriteStartElement ("any");
xtw.WriteEndElement ();
}
else
WriteComplexTypeSample (xtw, (XmlSchemaComplexType)
elem.SchemaType, root);
}
void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
{
XmlSchemaComplexType ctype = FindComplexTyype (qname);
if (ctype != null) {
WriteComplexTypeSample (xtw, ctype, qname);
return;
}
if (currentUse == SoapBindingUse.Encoded) {
string pref = xtw.LookupPrefix (rootName.Namespace);
if (pref == null) pref = "q1";
xtw.WriteStartElement (pref, rootName.Name,
rootName.Namespace);
ns = "";
}
else
xtw.WriteStartElement (rootName.Name, rootName.Namespace);
if (id != -1)
{
xtw.WriteAttributeString ("id", "id" + id);
if (rootName != arrayType)
xtw.WriteAttributeString ("type",
XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
}
xtw.WriteEndElement ();
}
if (prev > 1)
return;
recursed_types [stype] = ++prev;
if (stype.Particle != null)
WriteParticleComplexContent (xtw, ns, stype.Particle);
else
{
if (stype.ContentModel is XmlSchemaSimpleContent)
WriteSimpleContent (xtw,
(XmlSchemaSimpleContent)stype.ContentModel);
else if (stype.ContentModel is XmlSchemaComplexContent)
WriteComplexContent (xtw, ns,
(XmlSchemaComplexContent)stype.ContentModel);
}
prev = recursed_types [stype];
recursed_types [stype] = --prev;
}
// refAttr.Form; TODO
if (!attr.RefName.IsEmpty) {
refAttr = FindRefAttribute (attr.RefName);
if (refAttr == null) throw new
InvalidOperationException ("Global attribute not found: " + attr.RefName);
}
string val;
if (!refAttr.SchemaTypeName.IsEmpty) val =
FindBuiltInType (refAttr.SchemaTypeName);
else val = FindBuiltInType ((XmlSchemaSimpleType)
refAttr.SchemaType);
if (anyat != null)
xtw.WriteAttributeString ("custom-attribute","value");
}
if (particle is XmlSchemaSequence) {
WriteSequenceContent (xtw, ns,
((XmlSchemaSequence)particle).Items, multiValue);
}
else if (particle is XmlSchemaChoice) {
if (((XmlSchemaChoice)particle).Items.Count == 1)
WriteSequenceContent (xtw, ns,
((XmlSchemaChoice)particle).Items, multiValue);
else
WriteChoiceContent (xtw, ns,
(XmlSchemaChoice)particle, multiValue);
}
else if (particle is XmlSchemaAll) {
WriteSequenceContent (xtw, ns,
((XmlSchemaAll)particle).Items, multiValue);
}
}
if (item is XmlSchemaElement)
{
XmlSchemaElement elem = (XmlSchemaElement) item;
XmlSchemaElement refElem;
if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
else refElem = elem;
xtw.WriteAttributeString ("arrayType",
SoapEncodingNamespace, qname.Name + "[2]");
WriteContentItem (xtw, ns, elem, true);
return;
}
}
if (ext != null) {
// Add the members of this map
WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
if (ext.Particle != null)
WriteParticleComplexContent (xtw, ns, ext.Particle);
}
XmlSchemaAttributeGroupRef gref = ob as
XmlSchemaAttributeGroupRef;
if (gref != null)
{
XmlSchemaAttributeGroup grp =
(XmlSchemaAttributeGroup) schemas.Find (gref.RefName,
typeof(XmlSchemaAttributeGroup));
att = FindArrayAttribute (grp.Attributes);
if (att != null) return att;
}
}
return null;
}
</script>
<head runat="server">
<%
Response.Write ("<link rel=\"alternate\" type=\"text/xml\" href=\"" +
Request.FilePath + "?disco\"/>");
%>
<title><%=WebServiceName%> Web Service</title>
<style type="text/css">
BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-
size: x-small}
TABLE { font-size: x-small }
.title { color:dimgray; font-family: Arial; font-size:20pt; font-
weight:900}
.operationTitle { color:dimgray; font-family: Arial; font-size:15pt;
font-weight:900}
.method { font-size: x-small }
.bindingLabel { font-size: x-small; font-weight:bold; color:darkgray;
line-height:8pt; display:block; margin-bottom:3px }
.label { font-size: small; font-weight:bold; color:darkgray }
.paramTable { font-size: x-small }
.paramTable TR { background-color: gainsboro }
.paramFormTable { font-size: x-small; padding: 10px; background-color:
gainsboro }
.paramFormTable TR { background-color: gainsboro }
.paramInput { border: solid 1px gray }
.button {border: solid 1px gray }
.smallSeparator { height:3px; overflow:hidden }
.panel { background-color:whitesmoke; border: solid 1px silver; border-
top: solid 1px silver }
.codePanel { background-color: white; font-size:x-small; padding:7px;
border:solid 1px silver}
.code-xml { font-size:10pt; font-family:courier }
.code-cs { font-size:10pt; font-family:courier }
.code-vb { font-size:10pt; font-family:courier }
.tabLabelOn { font-weight:bold }
.tabLabelOff {color: darkgray }
.literal-placeholder {color: darkblue; font-weight:bold}
A:link { color: black; }
A:visited { color: black; }
A:active { color: black; }
A:hover { color: blue }
</style>
}
}
}
re = /\t/g;
text = text.replace (re, " ");
re = /\<\s*(\/?)\s*(.*?)\s*(\/?)\s*\>/g;
text = text.replace (re,"{blue:<$1}{maroon:$2}{blue:$3>}");
re = /{(\w*):(.*?)}/g;
text = text.replace (re,"<span style='color:$1'>$2</span>");
re = /"(.*?)"/g;
text = text.replace (re,"\"<span style='color:purple'>$1</span>\"");
re = /\r\n|\r|\n/g;
text = text.replace (re, "<br/>");
return text;
}
function getReq () {
if (window.XMLHttpRequest) {
return new XMLHttpRequest(); // Firefox, Safari, ...
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function clearForm ()
{
document.getElementById("testFormResult").style.display="none";
}
</script>
</head>
<body>
<div class="title" style="margin-left:20px">
<span class="label">Web Service</span><br>
<%=WebServiceName%>
</div>
<!--
**********************************************************
Left panel
-->
</td><td class="panel">
<!--
**********************************************************
Web service overview
-->
<!--
**********************************************************
Operation description
-->
<span class="operationTitle"><%=CurrentOperationName%></span>
<br><br>
<% WriteTabs (); %>
<br><br><br>
<span class="label">Remarks</span>
<div class="smallSeparator"></div>
<%=OperationDocumentation%>
<br><br>
<span class="label">Technical information</span>
<div class="smallSeparator"></div>
Format: <%=CurrentOperationFormat%>
<br>Supported protocols: <%=CurrentOperationProtocols%>
<% } %>
<!--
**********************************************************
Operation description - Test form
-->
<!--
**********************************************************
Operation description - Message Layout
-->
The following are sample SOAP requests and responses for each protocol
supported by this method:
<br/><br/>
<% } %>
<%} else if (CurrentPage == "proxy") {%>
<!--
**********************************************************
Client Proxy
-->
<form action="<%=PageName%>" name="langForm" method="GET">
Select the language for which you want to generate a proxy
<input type="hidden" name="page" value="<%=CurrentPage%>">
<SELECT name="lang" onchange="langForm.submit()">
<%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
<%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
</SELECT>
</form>
<br>
<span class="label"><%=CurrentProxytName%></span>
<a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
<br><br>
<div class="codePanel">
<div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
</div>
<%} else if (CurrentPage == "wsdl") {%>
<!--
**********************************************************
Service description
-->
<% if (descriptions.Count > 1 || schemas.Count > 1) {%>
The description of this web service is composed by several documents. Click
on the document you want to see:
<ul>
<%
for (int n=0; n<descriptions.Count; n++)
Response.Write ("<li><a href='" + PageName + "?" +
GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " +
descriptions[n].TargetNamespace + "</a></li>");
for (int n=0; n<schemas.Count; n++)
Response.Write ("<li><a href='" + PageName + "?" +
GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " +
schemas[n].TargetNamespace + "</a></li>");
%>
</ul>
<%}%>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</td>
<td width="20px"></td>
</tr>
</table>
</body>
</html>