- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有 ASMX 网络服务,我想以 JSON 格式返回结果。当我的网络方法没有参数时它工作正常。
[WebService(Namespace = "http://www.arslanonline.com/")]
[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 AuthService : System.Web.Services.WebService {
public AuthService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public string Authenticate(string username, string password, string appId)
{
return ToJson("Hello World");
}
public static string ToJson(object obj)
{
return JsonConvert.SerializeObject(obj);
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Test()
{
return ToJson("Hello World");
}
当我以这种方式调用我的测试 Web 方法时它工作正常
string url= "http://localhost:45548/Moves/AuthService.asmx/Test";
string dataToPost= "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json;";
request.BeginGetRequestStream(new AsyncCallback(DoHTTPPostRequestReady), new HttpWebRequestData<string>()
{
Request = request,
Data = dataToPost
});
并返回我的 JSON 结果。但是对于我的第二种方法 Authenticate 来说,它采用了一些我要求的参数
string url= "http://localhost:45548/Moves/AuthService.asmx/Authenticate";
string dataToPost= "username=ABC&password=123&appid=1";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json;";
request.BeginGetRequestStream(new AsyncCallback(DoHTTPPostRequestReady), new HttpWebRequestData<string>()
{
Request = request,
Data = dataToPost
});
它给我 Not Found Error
但是当我更改为 request.ContentType = "application/x-www-form-urlencoded"
时;它工作正常,并以 XML 但不是 JSON 格式返回结果。为什么会发生这种情况,任何人都可以告诉我代码中的故障在哪里。
最佳答案
使用 void 作为方法的返回类型。
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void Test()
{
System.Web.HttpContext.Current.Response.Write(ToJson("Hello World"));
}
关于c# - ASMX 网络服务中的 JSON 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17403244/
我有一个 asmx 服务,它接受一个 int 参数。我可以打开服务的 URL 并查看服务描述屏幕。从这里我可以将查询参数输入表单并调用 Web 服务。 有没有办法直接从 URL/查询字符串调用 Web
我有一个通过 SSL 连接运行良好的 ASMX Web 服务,但我想让这些 Web 服务在没有 SSL 的情况下无法访问。 在网络表单中,我只会使用以下代码: if (!Request.IsSecur
似乎 ASMX 隐含地不允许使用 OPTIONS 动词。我发布这个问题是因为我使用带有 POST 的 jQuery AJAX 调用,它首先在发出 POST 动词**之前向服务器查询可用的选项。 默认情
所以我发现自己遇到了一个难题。我们的应用程序中有一些旧的 asmx Web 服务,多年来一直运行良好。 突然间,他们停止了构建服务器(CI)上的工作。我说停止工作,因为即使当我导航到服务时显示服务描述
我有一个 C# .net Web 服务,需要限制其访问。我已经要求我的消费者使用用户名和密码来调用该服务。但是,有没有办法限制对实际 asmx 页面和 WSDL 的访问?我需要通过用户名/密码和 IP
描述 我有一个遗留类型 HttpRequestScoped以及使用该服务的遗留 Web 服务。为了解决遗留问题中的服务,我有一个全局解析器。这一切在 1.4 中运行良好,现在我正在使用 2.1.12,
有谁知道 SQL Server Reporting Services 中的两个 Web 服务端点 ReportService2005.asmx 和 ReportExecution2005.asmx 之
我有一个基本的 ASMX 服务,我正在尝试运行它(我宁愿使用 WCF,但无法让服务器使用它)。它在没有安全设置的情况下运行良好,但是一旦我打开安全性,我就会得到: The HTTP request i
在设计 ASMX 网络服务时,对您可以使用的类型有某种限制(序列化/反序列化)。 谁能告诉我这些限制是什么?是否可以通过在代码中添加serializable属性来绕过? 最佳答案 没有。传统的 ASM
我已经使用 CheckVat 方法创建了 ASMX 网络服务。如果我从 https://my.domain.com/VatValidation.asmx 调用此方法,我会得到成功的 json 响应,如
我正在通过经典的 asmx 网络服务传输一个大的压缩文本文件。我这样做的原因是文件的大小是 20 MB 解压缩,4MB 压缩。 这是方法。如有必要,我会提供更多信息。 [WebMethod]
我需要在客户端页面中使用 JavaScript 调用我的 Web 服务方法。我认为我没有正确引用这一点,希望您能帮助解决这一问题。 错误消息显示“CalendarHandler 未定义”。
我正在使用 ASP.NET 和 asmx 服务来访问我的 SQL 数据库的数据。 该服务既称为客户端又称为后端。 该网站将供我们的内部员工和我们的客户使用。 asmx 服务中有一些方法,如果它们未通过
我在一台服务器 1 上编写了一个 asmx 服务,在另一台服务器 2 上编写了 asp.net/c#。 我要转一个dictionary从 srv1 到 srv2。我读到 Dictionary is n
所以我在 Visual Studio 2010 中创建了一个 Web 服务。为了将它部署到 IIS Web 服务器上,我将 service.asmx、web.config 和 bin 复制到服务器(w
我有以下 ASMX 网络服务: // removed for brevity // namespace AtomicService { [WebService(Namespace = "htt
我在我的应用程序中使用第三方支付网关。支付网关提供商为集成提供了测试 asmx HTTPS URL,它有一些方法。使用 HttpWebRequest 我集成到我的应用程序中。我正在发送 SOAPReq
我正在尝试将国家/地区 Web 服务添加到下拉列表中。我已经添加了 Web 引用并拥有 discomap 和 wsdl 文件。 这是我的代码隐藏: net.webservicex.www.countr
我有一个扩展名为 .asmx 的网络服务,它指向我的网络应用程序中的一个类。添加一些代码以在应用程序启动时输出调试日志后,我可以看到每次用户访问该页面时都会创建一个新的调试日志。 我希望我可以将此 W
我有一个 asmx 服务,这些方法返回具有原始数据类型属性的自定义类。当这些属性为 null 时,它们将被排除在服务返回的 xml 之外。我希望该服务仍返回 xml 中的属性,但没有值。有办法做到这一
我是一名优秀的程序员,十分优秀!