asp.net webservice出错

时间:2014-11-27 06:28:36

标签: c# asp.net web-services asmx

我的asmx webservice就像这样

   using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using Newtonsoft.Json;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class GetRateRequestData : WebService
{
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string GetParcelLookupData()
    {

            return JsonConvert.SerializeObject(dataSet, Formatting.Indented);

    }
}

我正试图像这样访问浏览器中的数据

http://localhost:53569/services/GetRateRequestData.asmx/GetParcelLookupData/

但这会引发错误,如

    System.InvalidOperationException: GetParcelLookupData/ Web Service method name is not valid.
   at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

我是webservices的新手,任何人都可以指出我在这里做错了吗?

1 个答案:

答案 0 :(得分:1)

您可以修饰您的方法以允许HTTP GET请求

[WebMethod]  
[ScriptMethod(UseHttpGet=true)]
public string MyMethod(int myint)
{
    // ... code here
}

并按以下方式更改您的配置

<system.web>
<webServices>
  <protocols>
    <add name="HttpGet"/>
</protocols>
</webServices>