介于微软的SilverLight写了一个即时在线的白板程序,但是部署上出现一些问题,本机调试的时候出现一个错误,[UnexpectedHttpResponseCode] 解决方案网上也就是有了的,也就是在目录地下增加一个XML策略文件,这里我也就不说了,但是在部署到虚拟空间的时候却发现一个致命的问题,就是无论如何,WebService都不好用,也就是无法保存和读取,更别说及时更新了,不断地折腾之后,发现问题可能出在那个XML文件上,故删除之,然后重新配置完成并完成部署。OK,Done !
演示地址,大家可以看这里
http://icesun963.myidc.info/
用的是ASP.net 2.0的虚拟主机,按微软的说法,不管什么系统都能支持XAML的部署,也就是一个简单的HTML没什么区别,不需要添加midi也不需要任何设置。这里是我的html文件,

<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>

<
html
xmlns
="http://www.w3.org/1999/xhtml"
>

<!--
saved from url=(0014)about:internet
-->

<
head
>

<
title
>
银色光环 - 在线白板
</
title
>



<
style
type
="text/css"
>
...


html, body {...}{

height: 100%;

overflow: auto;

}


body {...}{

padding: 0;

margin: 0;

}


#silverlightControlHost {...}{

height: 100%;

}

</
style
>



<
script
type
="text/javascript"
>
...


function onSilverlightError(sender, args) ...{


if (args.errorType == "InitializeError") ...{

var errorDiv = document.getElementById("errorLocation");

if (errorDiv != null)

errorDiv.innerHTML = args.errorType + "- " + args.errorMessage;

}

}

</
script
>

</
head
>


<
body
>

<!--
Runtime errors from Silverlight will be displayed here.

This will contain debugging @R_363_4045@ion and should be removed or hidden when debugging is completed
-->

<
div
id
='errorLocation'
style
="font-size: small;color: Gray;"
></
div
>


<
div
id
="silverlightControlHost"
>

<
object
data
="data:application/x-silverlight,"
type
="application/x-silverlight-2-b1"
width
="810"
height
="610"
>

<
param
name
="source"
value
="SilverlightApp.xap"
/>

<
param
name
="onerror"
value
="onSilverlightError"
/>

<
param
name
="background"
value
="white"
/>


<
a
href
="http://go.microsoft.com/fwlink/?LinkID=108182"
style
="text-decoration: none;"
>

<
img
src
="http://go.microsoft.com/fwlink/?LinkId=108181"
alt
="Get Microsoft Silverlight"
style
="border-style: none"
/>

</
a
>

</
object
>

<
iframe
style
='visibility:hidden;height:0;width:0;border:0px'
></
iframe
>

</
div
>

</
body
>

</
html
>

注意,上面的 SilverlightApp.xap 应该改为 SilverlightApp.zip
xap 本机测试用的 :) 懒得改咯。
由于SL的DLL版本和.net版本有很大的区别,所以在通讯上也有很多的问题,当然你可以说自己格式化,那么和自己写tcp的难度没有什么区别了,但是在。net中序列化还是很好用的,即使你的类很显然处于不同的版本下。
比如一个简单的class1 如果你在SL下使用 并且也在WS上添加的话,使用的时候很显然的会给你一个类型错误的异常,你就不得不进行一次转换。这也是代价之一。
或者你可以尝试我现在使用的办法,使用byte[] 或者 字符串 我这里是压缩之后通过 byte[] 传输,传输过程是这样的。

[Serializable]

public
abstract
class
WBMessage


...
{

public string id ;



public enum whiteboard_MESSAGE_TYPE


...{

//enWBBegin=0,

enWBIMHERE,

enWBLine = 1,

//enWBRectangle,

//enWBEllipse,

//enWBClearScreen,

enWBUpdateLine = 4,

enWBDelLine = 5,

enWBEnd = 6,

enWBSave = 7,

enWBLoad = 8,

enMsgList=100

};


public abstract whiteboard_MESSAGE_TYPE MessageType


...{

get;

}


public WBMessage()


...{

}


public byte[] Data;



}
这里是基础的用来通讯的类
来看看传输类
所有的消息都是通过继承这个类的。

public
static
string
global
=
string
.Empty;

public
static
void
Send(WBMsgDrawLine msg)


...
{

BasicHttpBinding bind = new BasicHttpBinding();

EndpointAddress endpoint = new EndpointAddress("http://icesun963.myidc.info/MapService.asmx");


SilverlightClassLibrary.MapService.MapServiceSoapClient Cilent = new SilverlightClassLibrary.MapService.MapServiceSoapClient();



Cilent.MSGRequestCompleted += new EventHandler<SilverlightClassLibrary.MapService.MSGRequestCompletedEventArgs>(Cilent_MSGRequestCompleted);


msg.Data = SerializationHelper.SerialiazetoByteArray(msg);



WBMsgDrawLine wbmsg = new WBMsgDrawLine(msg);


wbmsg.id = global;

Cilent.MSGRequestAsync(SerializationHelper.SerialiazetoByteArray(wbmsg), (int)msg.MessageType);


}
呵呵,序列化自己,然后包装成传输类,传递 :)
暂时就这么多把,自己的一点小心得,希望对大家有用!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。