//客户端代码
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1" ScriptMode="Debug">
<Services>
<asp:ServiceReference Path="Services/ReturnXmlService.asmx" InlineScript="true" />
</Services>
</asp:ScriptManager>
<input type="button" value="GetXmlDocument" onclick="ReturnXmlService.GetXmlDocument(onSucceeded);" /><br /><br />
<input type="button" value="GetXmlElement" onclick="ReturnXmlService.GetXmlElement(onSucceeded);" /><br /><br />
<input type="button" value="GetEmployee" onclick="ReturnXmlService.GetEmployee(onSucceeded);" /><br /><br />
<input type="button" value="GetXmlString" onclick="ReturnXmlService.GetXmlString(onSucceeded);" /><br /><br />
<input type="button" value="GetSerializedString" onclick="ReturnXmlService.GetSerializedString(onSucceeded);" />
<script language="javascript" type="text/javascript">
function onSucceeded(result)
{
alert(result.xml);
}
</script>
</form>
//服务端代码
<asp:ScriptManager runat="server" ID="ScriptManager1" ScriptMode="Debug">
<Services>
<asp:ServiceReference Path="Services/ReturnXmlService.asmx" InlineScript="true" />
</Services>
</asp:ScriptManager>
<input type="button" value="GetXmlDocument" onclick="ReturnXmlService.GetXmlDocument(onSucceeded);" /><br /><br />
<input type="button" value="GetXmlElement" onclick="ReturnXmlService.GetXmlElement(onSucceeded);" /><br /><br />
<input type="button" value="GetEmployee" onclick="ReturnXmlService.GetEmployee(onSucceeded);" /><br /><br />
<input type="button" value="GetXmlString" onclick="ReturnXmlService.GetXmlString(onSucceeded);" /><br /><br />
<input type="button" value="GetSerializedString" onclick="ReturnXmlService.GetSerializedString(onSucceeded);" />
<script language="javascript" type="text/javascript">
function onSucceeded(result)
{
alert(result.xml);
}
</script>
</form>
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlNode GetXmlDocument()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Employee><Name>Jeffrey Zhao</Name><Salary>1000</Salary></Employee>");
return doc;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlNode GetXmlElement()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Employee><Name>Jeffrey Zhao</Name><Salary>1000</Salary></Employee>");
return doc.DocumentElement;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public Employee GetEmployee()
{
return new Employee("Jeffrey Zhao", 1000);
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public string GetXmlString()
{
return "<Employee><Name>Jeffrey Zhao</Name><Salary>1000</Salary></Employee>";
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml, XmlSerializeString = true)]
public string GetSerializedString()
{
return "<Employee><Name>Jeffrey Zhao</Name><Salary>1000</Salary></Employee>";
}
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlNode GetXmlDocument()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Employee><Name>Jeffrey Zhao</Name><Salary>1000</Salary></Employee>");
return doc;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlNode GetXmlElement()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Employee><Name>Jeffrey Zhao</Name><Salary>1000</Salary></Employee>");
return doc.DocumentElement;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public Employee GetEmployee()
{
return new Employee("Jeffrey Zhao", 1000);
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public string GetXmlString()
{
return "<Employee><Name>Jeffrey Zhao</Name><Salary>1000</Salary></Employee>";
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml, XmlSerializeString = true)]
public string GetSerializedString()
{
return "<Employee><Name>Jeffrey Zhao</Name><Salary>1000</Salary></Employee>";
}
浙公网安备 33010602011771号