如何将 asmx 服务转换为 rest 以使用 URL 调用
How to convert asmx service to rest to invoke with URL
我已经创建了 asmx 服务,如何通过 "URL" 调用它?
这是我的代码:
[WebMethod]
public string start(string id, string name)
{
string newname = name;
return newname;
}
这是我现在的 URL:
url = "http://localhost:XXXXX/WebService.asmx/start?id=" +id+ "&name="+name;
这是我的 "Web.config":
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5">
</compilation>
<httpRuntime maxRequestLength="1000000"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
您可以修饰您的方法以允许 HTTP GET 请求
[WebMethod]
[ScriptMethod(UseHttpGet=true)]
public string start(string id, string name)
{
string newname = name;
return newname;
}
并在 web.config 文件中执行以下操作
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
</protocols>
Setting the UseHttpGet property to true might pose a security risk for
your application if you are working with sensitive data or
transactions. In GET requests, the message is encoded by the browser
into the URL and is therefore an easier target for tampering.
Note that this method of performing GET requests does come with some
security risks. According to the MSDN documentation for UseHttpGet:
希望对您有所帮助
我已经创建了 asmx 服务,如何通过 "URL" 调用它?
这是我的代码:
[WebMethod]
public string start(string id, string name)
{
string newname = name;
return newname;
}
这是我现在的 URL:
url = "http://localhost:XXXXX/WebService.asmx/start?id=" +id+ "&name="+name;
这是我的 "Web.config":
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5">
</compilation>
<httpRuntime maxRequestLength="1000000"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
您可以修饰您的方法以允许 HTTP GET 请求
[WebMethod]
[ScriptMethod(UseHttpGet=true)]
public string start(string id, string name)
{
string newname = name;
return newname;
}
并在 web.config 文件中执行以下操作
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
</protocols>
Setting the UseHttpGet property to true might pose a security risk for your application if you are working with sensitive data or transactions. In GET requests, the message is encoded by the browser into the URL and is therefore an easier target for tampering.
Note that this method of performing GET requests does come with some security risks. According to the MSDN documentation for UseHttpGet:
希望对您有所帮助