在一个html里面调用其他机器的wcf服务,请问url是个什么规则啊。
我现在已经搭建好一台wcf服务,可以通过http://pc1234567/Service/Service1.svc来访问;并且在本机上面新建一个asp.net的web项目,在新建的aspx页面中成功访问了服务器并取得返回值。
现在是因为手机也需要访问,暂时作了个一个html页面,在jquery里面通过json访问wcf服务器,一直失败。但是如果我把这个页面加在到本地wcf服务器的工程里面,通过:Service1.svc/hello可以访问到,但是如果直接访问wcf服务器: http://localhost:2999/Service/Service1.svc/hello就不行了。 ar obj = { item: {item1:1,item2:2}
};
var arg = JSON.stringify(obj);
$.ajax({
type: "Post",
datatype: "json",
url: "http://pc1234567/Service/Service1.svc/hello",
data: arg,
contentType: "application/json; charset=utf-8",
beforeSend: function (xhr) {
xhr.setRequestHeader("Accept", "application/json")
},
success: function (data, textStatus, xhr) {
if (data != null) { $("#txtmsg").val(data.msg);
}
},
error: function (xhr, textStatus, errorThrown) {
alert(xhr.responseText);
}
});
我现在已经搭建好一台wcf服务,可以通过http://pc1234567/Service/Service1.svc来访问;并且在本机上面新建一个asp.net的web项目,在新建的aspx页面中成功访问了服务器并取得返回值。
现在是因为手机也需要访问,暂时作了个一个html页面,在jquery里面通过json访问wcf服务器,一直失败。但是如果我把这个页面加在到本地wcf服务器的工程里面,通过:Service1.svc/hello可以访问到,但是如果直接访问wcf服务器: http://localhost:2999/Service/Service1.svc/hello就不行了。 ar obj = { item: {item1:1,item2:2}
};
var arg = JSON.stringify(obj);
$.ajax({
type: "Post",
datatype: "json",
url: "http://pc1234567/Service/Service1.svc/hello",
data: arg,
contentType: "application/json; charset=utf-8",
beforeSend: function (xhr) {
xhr.setRequestHeader("Accept", "application/json")
},
success: function (data, textStatus, xhr) {
if (data != null) { $("#txtmsg").val(data.msg);
}
},
error: function (xhr, textStatus, errorThrown) {
alert(xhr.responseText);
}
});
解决方案 »
- ASP.NET Datagrid checkbox 批量下载
- 请教jquery获取单选按钮的NAME和选择值
- 各位仁兄义姐,如何将网页强制设为首页?
- 图片上传预览问题
- 表头锁定可滚动的表格 - BizStruct 商业架构
- 如何实现像QQ邮箱的导航栏那样可以不刷新页面更换网页中容器?
- 关于窗口关闭的新问题,以及隐去IE的菜单栏、地址栏、状态栏的问题
- JS能否做到在链接时像ASP 一样用?后的信息来向一窗口传递参数?请高手指点! 多谢!!!
- <input type='text'>的内容改变时,弹出alert
- extjs6 关于grid假分页
- 怎样能知道自己的文件被别人修改了?
- 请问 这个分享到效果 怎么才能放到右侧
http://localhost:1336/Service1/Service1.svc/hello
错误信息:xhr.responseText都是空,什么都没有。
xhr.statusText: Bad Request
果然是URL不对阿
现在应用URL直接访问是建立一个服务器工厂。<%@ServiceHost Language="c#" Debug="true" Service="xx.xx" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>这样就能直接访问了,但是web.config里面的配置需要删掉。删掉之后,在asp.net的客户端却不能引用参照了,比较头疼。这个先结掉了