1 <%@ Import Namespace="System.Collections" %>
2 <%@ Import Namespace="System.IO" %>
3 <%@ Import Namespace="System.Xml.Serialization" %>
4 <%@ Import Namespace="System.Xml" %>
5 <%@ Import Namespace="System.Xml.Schema" %>
6 <%@ Import Namespace="System.Web.Services.Description" %>
7 <%@ Import Namespace="System" %>
8 <%@ Import Namespace="System.Globalization" %>
9 <%@ Import Namespace="System.Resources" %>
10 <%@ Import Namespace="System.Diagnostics" %>
11 <%@ Assembly name="System.Web.Services" %>
12 <%@ Page debug="true" %>
15 <script language="C#" runat="server">
17 ServiceDescriptionCollection descriptions;
20 string WebServiceName;
21 string WebServiceDescription;
24 string DefaultBinding;
26 string CurrentOperationName;
27 string CurrentOperationBinding;
28 string OperationDocumentation;
32 void Page_Load(object sender, EventArgs e)
34 descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
35 schemas = (XmlSchemas) Context.Items["schemas"];
37 ServiceDescription desc = descriptions [0];
38 Service service = desc.Services[0];
39 WebServiceName = service.Name;
40 DefaultBinding = desc.Bindings[0].Name;
41 WebServiceDescription = service.Documentation;
43 CurrentOperationName = Request.QueryString["op"];
44 CurrentOperationBinding = Request.QueryString["bnd"];
45 if (CurrentOperationName != null) BuildOperationInfo ();
47 PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
49 ArrayList list = new ArrayList ();
50 foreach (ServiceDescription sd in descriptions)
51 list.AddRange (sd.Bindings);
53 BindingsRepeater.DataSource = list;
57 void BuildOperationInfo ()
59 InParams = new ArrayList ();
60 OutParams = new ArrayList ();
62 Binding binding = FindBinding (CurrentOperationBinding);
63 PortType portType = descriptions.GetPortType (binding.Type);
64 Operation oper = FindOperation (portType, CurrentOperationName);
66 OperationDocumentation = oper.Documentation;
67 if (OperationDocumentation == null || OperationDocumentation == "")
68 OperationDocumentation = "No additional remarks";
70 foreach (OperationMessage opm in oper.Messages)
72 if (opm is OperationInput)
73 BuildParameters (InParams, opm);
74 else if (opm is OperationOutput)
75 BuildParameters (OutParams, opm);
78 InputParamsRepeater.DataSource = InParams;
79 InputFormParamsRepeater.DataSource = InParams;
80 OutputParamsRepeater.DataSource = OutParams;
83 void BuildParameters (ArrayList list, OperationMessage opm)
85 Message msg = descriptions.GetMessage (opm.Message);
86 if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
88 MessagePart part = msg.Parts[0];
89 XmlSchemaComplexType ctype;
90 if (part.Element == XmlQualifiedName.Empty)
92 ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
96 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
97 ctype = (XmlSchemaComplexType) elem.SchemaType;
99 XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
100 if (seq == null) return;
102 foreach (XmlSchemaObject ob in seq.Items)
104 Parameter p = new Parameter();
105 p.Description = "No additional remarks";
107 if (ob is XmlSchemaElement)
109 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
111 p.Type = selem.SchemaTypeName.Name;
123 foreach (MessagePart part in msg.Parts)
125 Parameter p = new Parameter ();
126 p.Description = "No additional remarks";
128 if (part.Element == XmlQualifiedName.Empty)
129 p.Type = part.Type.Name;
132 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
133 p.Type = elem.SchemaTypeName.Name;
140 XmlSchemaElement GetRefElement (XmlSchemaElement elem)
142 if (!elem.RefName.IsEmpty)
143 return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
148 Binding FindBinding (string portName)
150 Service service = descriptions[0].Services[0];
151 foreach (Port port in service.Ports)
152 if (port.Name == portName)
153 return descriptions.GetBinding (port.Binding);
157 Operation FindOperation (PortType portType, string name)
159 foreach (Operation oper in portType.Operations)
160 if (oper.Name == name) return oper;
164 string FormatBindingName (string name)
166 if (name == DefaultBinding) return "Methods";
167 else return "Methods for binding<br>" + name;
176 public string Name { get { return name; } set { name = value; } }
177 public string Type { get { return type; } set { type = value; } }
178 public string Description { get { return description; } set { description = value; } }
184 <style type="text/css">
185 BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
186 TABLE { font-size: x-small }
187 .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
188 .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
189 .method { font-size: x-small }
190 .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
191 .label { font-size: x-small; font-weight:bold; color:darkgray }
192 .paramTable { font-size: x-small }
193 .paramTable TR { background-color: gainsboro }
194 .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
195 .paramFormTable TR { background-color: gainsboro }
196 .paramInput { border: solid 1px gray }
197 .button {border: solid 1px gray }
198 .smallSeparator { height:3px; overflow:hidden }
199 .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver }
200 A:link { color: black; }
201 A:visited { color: black; }
202 A:active { color: black; }
203 A:hover { color: blue }
208 <div class="title" style="margin-left:20px">
209 <span class="label">Web Service</span><br>
212 <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
213 <tr valign="top"><td width="150px" class="panel">
214 <a class="method" href='<%=PageName%>'>Overview</a><br>
215 <div class="smallSeparator"></div>
216 <a class="method" href='<%=PageName + "?wsdl"%>'>Service Description</a>
217 <div class="smallSeparator"></div>
218 <a class="method" href='<%=PageName + "?code=cs"%>'>C# proxy</a>
220 <asp:repeater id="BindingsRepeater" runat=server>
221 <itemtemplate name="itemtemplate">
222 <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
223 <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
225 <a class="method" href="<%#PageName%>?op=<%#DataBinder.Eval(Container.DataItem, "Name")%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#DataBinder.Eval(Container.DataItem, "Name")%></a>
226 <div class="smallSeparator"></div>
233 </td><td class="panel">
235 <% if (CurrentOperationName == null) {%>
236 <p class="label">Web Service Overview</p>
237 <%#WebServiceDescription%>
239 <span class="operationTitle"><%#CurrentOperationName%></span>
241 <span class="label">Input Parameters</span>
242 <% if (InParams.Count == 0) { %>
243 <br>No input parameters<br>
245 <table class="paramTable" cellspacing="1" cellpadding="5">
246 <asp:repeater id="InputParamsRepeater" runat=server>
249 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
250 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
258 <% if (OutParams.Count > 0) { %>
259 <span class="label">Output Parameters</span>
260 <table class="paramTable" cellspacing="1" cellpadding="5">
261 <asp:repeater id="OutputParamsRepeater" runat=server>
264 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
265 <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
272 <span class="label">Remarks</span>
273 <br><%#OperationDocumentation%>
276 <span class="label">Test</span><br>
277 Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
278 <form action="<%#PageName%>/<%#CurrentOperationName%>" method="POST">
279 <table class="paramFormTable" cellspacing="0" cellpadding="3">
280 <asp:repeater id="InputFormParamsRepeater" runat=server>
283 <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
284 <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
288 <tr><td></td><td><input class="button" type="submit" value="Invoke"></td></tr>
293 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
295 <td withd="20px"></td>