我写了一个Web Service.asmx来为其他网站提供美元价格服务。 但当我将它发布到我的网站并进行测试时,我收到了这个例外:
测试表单仅适用于本地计算机的请求。
我在asmx文件中使用以下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// Summary description for Services
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Services : System.Web.Services.WebService
{
[WebMethod]
public string USD_Prices()
{
string UnitedStateDollar;
using (var Entity = new DataModel.DBEntities())
{
var UsdPrice = Entity.TblExchange.OrderByDescending(Exchange => Exchange.Id).Select(p => p.USDSell).Take(1).ToList();
UnitedStateDollar = UsdPrice[0].ToString();
}
return UnitedStateDollar;
}
}
那么问题是什么?....如果您想在线查看,地址是:
答案 0 :(得分:1)
在您的网络配置中添加此内容。
<configuration>
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</configuration>
答案 1 :(得分:0)
没问题。 Web服务没有表单。为了使用.NET中的Web服务,您可以添加作为服务引用并从客户端代码中调用它们。
旧式ASMX服务有一个可用于演示目的的表单,您可以在其中输入一些简单的值并调用POST以从服务中获取结果。这已在WCF服务中删除,因为真实世界的Web服务具有无法通过简单表单处理的复杂参数。
创建WCF服务而不是ASMX服务会好得多。 WCF服务更加合规,高效,灵活,可扩展(等等)。
在任何情况下,您都可以通过向项目添加服务参考来从其他客户端呼叫您的服务。这将创建一个代理类,它将服务的参数作为对象公开,端点作为客户端对象上的方法公开。