如何从.net中的不同命名空间调用web服务
好吧,我在这里有点麻烦。
当我尝试从属于 myproject.account.members 命名空间的页面调用 Web 服务
到属于 myproject.services 的 Web 服务时,我收到错误
///- ----修改:添加错误消息-----///
---------------------------
Message from webpage
---------------------------
responseText=
textStatus=error
errorThrown=Unknown
---------------------------
OK
---------------------------
例如。
来自 somepage.aspx 的 jquery ajax 调用属于 myproject.account.members,
$.ajax({
type: "POST",
url: '<%=ResolveUrl("~/Services/productService.asmx/getSomething") %>',
data: '',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result){
alert(result.d)
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert("responseText=" + XMLHttpRequest.responseText + "\ntextStatus=" + textStatus + "\nerrorThrown=" + errorThrown);
}
});
webservice 代码属于 myproject.Services
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace myproject.Services
{
/// <summary>
/// Summary description for productService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 productService : System.Web.Services.WebService
{
[WebMethod]
public String getSomething()
{
return "Hello World";
}
}
}
基本上,如果我更改命名空间我的网络服务从 myproject.Services 到 myproject.account.member 如果我从属于 myproject.account.members 命名空间的页面调用它,它就可以工作......但是它如果将命名空间设置为 myproject.Services
请帮忙..我该如何解决这个问题?如果我想从项目中的几个不同命名空间调用相同的服务怎么办?`在此处输入代码
ok i'm in a bit of a pickle here.
When i try to call a webservice from a page that belongs to myproject.account.members namespace
to a webservice that belongs to myproject.services i get an error
///-----modified: added error message-----///
---------------------------
Message from webpage
---------------------------
responseText=
textStatus=error
errorThrown=Unknown
---------------------------
OK
---------------------------
eg.
The jquery ajax call from somepage.aspx that belongs to myproject.account.members
$.ajax({
type: "POST",
url: '<%=ResolveUrl("~/Services/productService.asmx/getSomething") %>',
data: '',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result){
alert(result.d)
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert("responseText=" + XMLHttpRequest.responseText + "\ntextStatus=" + textStatus + "\nerrorThrown=" + errorThrown);
}
});
the webservice code belongs to myproject.Services
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace myproject.Services
{
/// <summary>
/// Summary description for productService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 productService : System.Web.Services.WebService
{
[WebMethod]
public String getSomething()
{
return "Hello World";
}
}
}
Basically if i change namespace of my webservice from myproject.Services to myproject.account.member it works if i call it from a page that belongs to myproject.account.members namespace... but it won't work if set the namespace to myproject.Services
please help.. how do i get around this? what if i want to call same service from several different namespaces within my project?`enter code here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您更改 Web 服务类背后的代码的命名空间时,请不要忘记在标记中也更改它 (
productService.asmx
):同时将:替换
为:
并获得更有意义的内容错误消息比您在问题中发布的消息使用 FireBug 或 Chrome 开发人员工具来查看它发送的确切 AJAX 请求。您将看到来自服务器的请求和响应。它将帮助您更好地了解代码的问题所在。
When you changed the namespace of the code behind class of the web service don't forget to change it in the markup as well (
productService.asmx
):Also replace:
with:
And to get a more meaningful error message than the one you have posted in your question use FireBug or Chrome Developer tools in order to see the exact AJAX request that it being sent. You will see the request and the response from the server. It will help you better understand what is wrong with your code.