gpt4 book ai didi

c# - 如何将 asmx 服务转换为 rest 以使用 URL 调用

转载 作者:太空宇宙 更新时间:2023-11-03 10:34:36 24 4
gpt4 key购买 nike

我已经创建了 asmx 服务,如何通过“URL”调用它?

这是我的代码:

[WebMethod]
public string start(string id, string name)
{
string newname = name;
return newname;
}

这是我当前的网址:

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:

希望对你有帮助

关于c# - 如何将 asmx 服务转换为 rest 以使用 URL 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28337588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com