我有2个网站提供相同的网络服务.对于Web服务SampleService,我想知道如何选择可供选择的Web服务器.
网站服务网址:
问:如何根据用户选择以编程方式更改Web引用引用的站点?
我试图使用jQuery .load()从asmx Web服务获取直接html:
$( '#靶')负载( 'MyService.asmx/GetHtml');
在.NET代码中,GetHtml()以字符串形式返回:
[WebMethod(EnableSession = false)]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
public string GetHtml()
{
return "<span>Hi</span>";
}
Run Code Online (Sandbox Code Playgroud)
返回:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"><span>Hi</span></string>
Run Code Online (Sandbox Code Playgroud)
请注意,字符串已编码.使用该编码,$ .load无法正常工作.显示的文本实际上显示了标签.
如何让WebMethod调用才能返回?
<span>Hi</span>
Run Code Online (Sandbox Code Playgroud) 我有一个.Net Web服务,它有一个接受我作为参数编写的接口的方法.我们称这个接口为ICustomer.
你会如何从PHP调用这个方法?
方法定义是
[WebMethod]
public string RegisterCustomer(ICustomer customer)
{
...
}
Run Code Online (Sandbox Code Playgroud) 你认为这是一种检索通知的坏方法吗?这个WebMethod将通过JavaScript每10秒调用一次.有没有更好的方法呢?如果是这样请详细说明.谢谢.
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public int[] GetNotifications()
{
int[] Notifications = new int[3]{0, 0, 0};
if (HttpContext.Current.User.Identity.IsAuthenticated) {
string UserName = HttpContext.Current.User.Identity.Name;
Notifications[0] = Notification.GetAll(UserName, false).Count;
Notifications[1] = Message.GetAll(UserName, false).Count;
Notifications[2] = Friendship.GetFriends(UserName, true).Count;
}
return Notifications;
}
Run Code Online (Sandbox Code Playgroud) 我有几个关于Web服务的问题,如果有人能指出我正确的方向,我真的很感激.
在我的类库中,我有两个类:Hotel&RoomType.Hotel类包含RoomType对象的ArrayList.
在我的Web服务中,我有一个GetHotels方法如下:
[WebMethod]
[XmlInclude(typeof(Hotel))]
[XmlInclude(typeof(RoomType))]
public ArrayList GetHotels()
{
return Sistema.GetInstance().GetHotels();
}
Run Code Online (Sandbox Code Playgroud)
类Sistema中的GetHotels(),从数据库中检索信息并返回一个ArrayList.
我不得不使用XMLInclude因为我得到了:
类型酒店(或RoomType)不是预期的.使用XmlInclude或SoapInclude属性指定静态未知的类型
然后在我的Web应用程序中,我有这个代码:
WebService sample = new Service();
ArrayList hotels = service.GetHotels();
Run Code Online (Sandbox Code Playgroud)
这不编译,所以我不得不改为以下代码:
WebService sample = new Service();
object[] hotels = service.GetHotels();
Run Code Online (Sandbox Code Playgroud)
这是我的第一个问题:是否可以返回一个ArrayList,或者每次我必须将结果转换为ArrayList?
知道ArrayList包含Hotel对象,我添加了以下代码:
foreach (Hotel hotel in hotels)
{
...
}
Run Code Online (Sandbox Code Playgroud)
这个编译,但是当我执行时,我收到以下错误:
无法将类型为"System.Xml.XmlNode []"的对象强制转换为"Hotel".
所以,我的下一个问题是:如何将结果转换为Hotel对象并使用它?
如该主题所述.我试图从独立的.asmx Web服务访问我的Sitecore上下文.想知道这是否是一种正确的做法.
asmx ×6
asp.net ×3
c# ×3
web-services ×3
javascript ×1
jquery ×1
php ×1
sitecore ×1
webmethod ×1
winforms ×1