如何让webservice支持http.get调用
用C#写的web service,一个标准和Demo,可以支持http.post调用,但是不支持http.get调用,是什么原因呢,要在哪里加什么配置吗?请给个答案吧,谢谢!代码如下,非常简单,就是新建工程后的代码,只是想测试一下get调用的效果:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService1
{
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(string name)
{
return name + "Hello World";
}
}
} --------------------编程问答-------------------- [ServiceContract]
public inte易做图ce IService1
{
[OperationContract]
[WebGet(UriTemplate="Add/{x}/{y}",ResponseFormat=WebMessageFormat.Xml)]
int Add(string x, string y);
}
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/ --------------------编程问答--------------------
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
这不是说了么...把注释弄掉 就可以通过Jquery的ajax来调用webservice了.
--------------------编程问答-------------------- 是可以调用了,但是为什么只能这样调http://localhost/myweb/Service1.asmx?op=HelloWorld&name=1123
不能http://localhost/myweb/Service1.asmx/HelloWorld?name=1123
?
然后返回的值是整个一个html不是我要的效果呀
<html>
<head><link rel="alternate" type="text/xml" href="/myweb/Service1.asmx?disco" />
<style type="text/css">
BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; }
#content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; }
A:link { color: #336699; font-weight: bold; text-decoration: underline; }
A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; }
A:active { color: #336699; font-weight: bold; text-decoration: underline; }
A:hover { color: cc3300; font-weight: bold; text-decoration: underline; }
P { color: #000000; margin-top: 0px; margin-bottom: 12px; font-family: Verdana; }
pre { background-color: #e5e5cc; padding: 5px; font-family: Courier New; font-size: x-small; margin-top: -5px; border: 1px #f0f0e0 solid; }
td { color: #000000; font-family: Verdana; font-size: .7em; }
h2 { font-size: 1.5em; font-weight: bold; margin-top: 25px; margin-bottom: 10px; border-top: 1px solid #003366; margin-left: -15px; color: #003366; }
h3 { font-size: 1.1em; color: #000000; margin-left: -15px; margin-top: 10px; margin-bottom: 10px; }
ul { margin-top: 10px; margin-left: 20px; }
ol { margin-top: 10px; margin-left: 20px; }
li { margin-top: 10px; color: #000000; }
font.value { color: darkblue; font: bold; }
font.key { color: darkgreen; font: bold; }
font.error { color: darkred; font: bold; }
.heading1 { color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal; background-color: #003366; margin-top: 0px; margin-bottom: 0px; margin-left: -30px; padding-top: 10px; padding-bottom: 3px; padding-left: 15px; width: 105%; }
.button { background-color: #dcdcdc; font-family: Verdana; font-size: 1em; border-top: #cccccc 1px solid; border-bottom: #666666 1px solid; border-left: #cccccc 1px solid; border-right: #666666 1px solid; }
.frmheader { color: #000000; background: #dcdcdc; font-family: Verdana; font-size: .7em; font-weight: normal; border-bottom: 1px solid #dcdcdc; padding-top: 2px; padding-bottom: 2px; }
.frmtext { font-family: Verdana; font-size: .7em; margin-top: 8px; margin-bottom: 0px; margin-left: 32px; }
.frmInput { font-family: Verdana; font-size: 1em; }
.intro { margin-left: -15px; }
</style>
<title>
Service1 Web 鏈嶅姟
</title></head>
<body>
<div id="content">
<p class="heading1">Service1</p><br>
<span>
<p class="intro">鍗曞嚮<a href="Service1.asmx">姝ゅ</a>锛岃幏鍙栧畬鏁寸殑鎿嶄綔鍒楄〃銆?/p>
<h2>HelloWorld</h2>
<p class="intro"></p>
<h3>娴嬭瘯</h3>
鑻ヨ浣跨敤 HTTP POST 鍗忚瀵规搷浣滆繘琛屾祴璇曪紝璇峰崟鍑烩€滆皟鐢ㄢ€濇寜閽€?
<form target="_blank" action='http://localhost/myweb/Service1.asmx/HelloWorld' method="POST">
<table cellspacing="0" cellpadding="4" frame="box" bordercolor="#dcdcdc" rules="none" style="border-collapse: collapse;">
<tr>
<td class="frmHeader" background="#dcdcdc" style="border-right: 2px solid white;">鍙傛暟</td>
<td class="frmHeader" background="#dcdcdc">鍊?/td>
</tr>
<tr>
<td class="frmText" style="color: #000000; font-weight: normal;">name:</td>
<td><input class="frmInput" type="text" size="50" name="name"></td>
</tr>
<tr>
<td></td>
<td align="right"> <input type="submit" value="璋冪敤" class="button"></td>
</tr>
</table>
</form>
<span>
<h3>SOAP 1.1</h3>
<p>浠ヤ笅鏄?SOAP 1.2 璇锋眰鍜屽搷搴旂ず渚嬨€傛墍鏄剧ず鐨?font class=value>鍗犱綅绗?/font>闇€鏇挎崲涓哄疄闄呭€笺€?/p>
<pre>POST /myweb/Service1.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: <font class=value>length</font>
SOAPAction: "http://tempuri.org/HelloWorld"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/">
<name><font class=value>string</font></name>
</HelloWorld>
</soap:Body>
</soap:Envelope></pre>
<pre>HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: <font class=value>length</font>
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult><font class=value>string</font></HelloWorldResult>
</HelloWorldResponse>
</soap:Body>
</soap:Envelope></pre>
</span>
<span>
<h3>SOAP 1.2</h3>
<p>浠ヤ笅鏄?SOAP 1.2 璇锋眰鍜屽搷搴旂ず渚嬨€傛墍鏄剧ず鐨?font class=value>鍗犱綅绗?/font>闇€鏇挎崲涓哄疄闄呭€笺€?/p>
<pre>POST /myweb/Service1.asmx HTTP/1.1
Host: localhost
Content-Type: application/soap+xml; charset=utf-8
Content-Length: <font class=value>length</font>
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HelloWorld xmlns="http://tempuri.org/">
<name><font class=value>string</font></name>
</HelloWorld>
</soap12:Body>
</soap12:Envelope></pre>
<pre>HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: <font class=value>length</font>
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult><font class=value>string</font></HelloWorldResult>
</HelloWorldResponse>
</soap12:Body>
</soap12:Envelope></pre>
</span>
<span>
<h3>HTTP POST</h3>
<p>浠ヤ笅鏄?HTTP POST 璇锋眰鍜屽搷搴旂ず渚嬨€傛墍鏄剧ず鐨?font class=value>鍗犱綅绗?/font>闇€鏇挎崲涓哄疄闄呭€笺€?/p>
<pre>POST /myweb/Service1.asmx/HelloWorld HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: <font class=value>length</font>
<font class=key>name</font>=<font class=value>string</font></pre>
<pre>HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: <font class=value>length</font>
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"><font class=value>string</font></string></pre>
</span>
</span>
</body>
</html>
补充:.NET技术 , Web Services