惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
WordPress大学
WordPress大学
C
Check Point Blog
GbyAI
GbyAI
U
Unit 42
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Hugging Face - Blog
Hugging Face - Blog
Vercel News
Vercel News
博客园 - 【当耐特】
美团技术团队
小众软件
小众软件
S
SegmentFault 最新的问题
Jina AI
Jina AI
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Cloudflare Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog

博客园 - L.Zhang

.Net Remoting RMI框架 自己开发连接池 JDBC访问数据库 MyEclipse下开发Web Service 使用传统的XMLHttpRequest发出Ajax请求 XML CDATA XPath 数据库操作的sql脚本 直接选择排序 直接插入排序 气泡排序 Builder 生成器模式(创建型模式) Abstract Factory 抽象工厂模式(创建型模式) Factory Method 工厂方法模式(创建型模式) Singleton单件模式(创建型模式) 使用Profile Service 服务端如何使用Session 用Get方式访问
让服务端返回xml
L.Zhang · 2007-10-28 · via 博客园 - L.Zhang

//客户端代码

 <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>

//服务端代码

    [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>";
    }