如何部署Silverlight及Web Service
2012-11-22 16:18
218 查看
今天我们将介绍的是部署Silverlight及Web Service,本文作者本来以为是简单的事情,其实还是经历了很多挫折。
AD:
一直通过Visual Studio测试Silverlight,本以为部署到服务器上是很简单的事。
没想到遇到了很多麻烦,用了整整一天的时间搜索解决方案。
先说部署到xp系统下本地IIS,服务器win2003也一样。
如图,右击虚拟目录->属性->HTTP头->MIME类型。添加
扩展名: .xap
MIME类型:application/x-silverlight-app
扩展名: .xaml
MIME类型:application/xaml+xml
这样就可以正常显示Silverlight了。
如果你调用了Web Service,
并且你的Web Service就在承载Silverlight的网站下。如图
这样不会有跨域操作的麻烦。
但是你不能直接引用localhost这样的本地服务。
否则部署在服务器上调用不成。
我的方法是把这个服务先部署在本地IIS
然后添加服务引用。
比如地址是http://127.0.0.1:8088/sl/LinqXmlService.asmx
这时候不存在跨域操作,先测试成功。
之后打开服务引用目录,如图
把这里的文件全部用vs打开,然后Ctrl+H做替换,选择所有打开文档。
把http://127.0.0.1:8088/sl/LinqXmlService.asmx替换成
http://www.weiqi9d.com/LinqXmlService.asmx
即你的服务器地址。
我也不知道是怎样想到这样做的。试了一下,可以。
另外一个问题,服务器上仍然无法访问.xap不知道为什么。
我只好把.xap修改成.htm然后把这里也改了。
<param name="source" value="ClientBin/SilverlightApplication2.htm"/>
如图
这样,即使你的sl是用vs2010开发的,并且服务器没有安装.net 4.0也可以正常显示。
记录一下Silverlight调用Web Service的方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace SilverlightApplication2.Web
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
调用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication2
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
//创建Web Service对象
ServiceReference1.LinqXmlServiceSoapClient ws = new ServiceReference1.LinqXmlServiceSoapClient();
void Page_Loaded(object sender, RoutedEventArgs e)
{
AddEvent();
Bind();
}
//注册事件,有点类似Ajax的回调
private void AddEvent()
{
ws.HelloWorldCompleted += new EventHandler<ServiceReference1.HelloWorldCompletedEventArgs>(ws_HelloWorldCompleted);
}
//回调函数
void ws_HelloWorldCompleted(object sender, ServiceReference1.HelloWorldCompletedEventArgs e)
{
button1.Content += e.Result + " hi";
//MessageBox.Show(e.Result);
}
private void Bind()
{
ws.HelloWorldAsync();
}
}
}
希望对正在学习Silverlight的朋友有帮助,同时希望牛人解答我的疑惑。
原文链接:http://www.cnblogs.com/greatverve/archive/2010/12/23/silverlight-web-service.html
AD:
一直通过Visual Studio测试Silverlight,本以为部署到服务器上是很简单的事。
没想到遇到了很多麻烦,用了整整一天的时间搜索解决方案。
先说部署到xp系统下本地IIS,服务器win2003也一样。
如图,右击虚拟目录->属性->HTTP头->MIME类型。添加
扩展名: .xap
MIME类型:application/x-silverlight-app
扩展名: .xaml
MIME类型:application/xaml+xml
这样就可以正常显示Silverlight了。
如果你调用了Web Service,
并且你的Web Service就在承载Silverlight的网站下。如图
这样不会有跨域操作的麻烦。
但是你不能直接引用localhost这样的本地服务。
否则部署在服务器上调用不成。
我的方法是把这个服务先部署在本地IIS
然后添加服务引用。
比如地址是http://127.0.0.1:8088/sl/LinqXmlService.asmx
这时候不存在跨域操作,先测试成功。
之后打开服务引用目录,如图
把这里的文件全部用vs打开,然后Ctrl+H做替换,选择所有打开文档。
把http://127.0.0.1:8088/sl/LinqXmlService.asmx替换成
http://www.weiqi9d.com/LinqXmlService.asmx
即你的服务器地址。
我也不知道是怎样想到这样做的。试了一下,可以。
另外一个问题,服务器上仍然无法访问.xap不知道为什么。
我只好把.xap修改成.htm然后把这里也改了。
<param name="source" value="ClientBin/SilverlightApplication2.htm"/>
如图
这样,即使你的sl是用vs2010开发的,并且服务器没有安装.net 4.0也可以正常显示。
记录一下Silverlight调用Web Service的方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace SilverlightApplication2.Web
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
调用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication2
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
//创建Web Service对象
ServiceReference1.LinqXmlServiceSoapClient ws = new ServiceReference1.LinqXmlServiceSoapClient();
void Page_Loaded(object sender, RoutedEventArgs e)
{
AddEvent();
Bind();
}
//注册事件,有点类似Ajax的回调
private void AddEvent()
{
ws.HelloWorldCompleted += new EventHandler<ServiceReference1.HelloWorldCompletedEventArgs>(ws_HelloWorldCompleted);
}
//回调函数
void ws_HelloWorldCompleted(object sender, ServiceReference1.HelloWorldCompletedEventArgs e)
{
button1.Content += e.Result + " hi";
//MessageBox.Show(e.Result);
}
private void Bind()
{
ws.HelloWorldAsync();
}
}
}
希望对正在学习Silverlight的朋友有帮助,同时希望牛人解答我的疑惑。
原文链接:http://www.cnblogs.com/greatverve/archive/2010/12/23/silverlight-web-service.html
相关文章推荐
- Silverlight中如何获取当前xap文件的地址以及部署了当前xap的页面地址
- 银光中国网免费Silverlight空间Web Service部署方法
- 部署Silverlight及Web Service
- 如何创建可供Silverlight调用的SharePoint in-build web service
- 如何更改Web Service部署生成的App_Code.dll的名称
- 如何解决Silverlight配置部署的AG_E_RUNTIME_MANAGED_ASSEMBLY错误
- 如何解决Silverlight配置部署的AG_E_RUNTIME_MANAGED_ASSEMBLY错误
- 驰骋工作流程引擎,工作流程管理系统,BPM软件:如何部署silverlight程序?
- silverlight如何通过单独部署的WCF站点访问sharepoint2013的图片库
- 如何让VS 自动把 Silverlight 项目生成的 xap 文件部署到指定目录
- 瞧,Silverlight是如何被部署到客户机的
- 如何更改Web Service部署生成的App_Code.dll的名称
- 银光中国网免费Silverlight空间Web Service部署方法
- 银光中国网免费Silverlight空间Web Service部署方法
- mvc1 mvc2 mvc3 知识小差异,服务器上如何配置 mvc3 IIS6,IIS7.5 上部署 mvc3 和 silverlight
- 如何更改Web Service部署生成的App_Code.dll的名称
- 部署Silverlight及Web Service
- 一起谈.NET技术,部署Silverlight及Web Service
- 银光中国网免费Silverlight空间Web Service部署方法
- 如何更改Web Service部署生成的App_Code.dll的名称