Visual Studio has been used to test Silverlight. I thought it was very easy to deploy it on the server.
I did not expect to encounter a lot of trouble. I spent a whole day searching for a solution.
Deploy IIS locally on the Windows XP system. The same is true for the server win2003.
, Right-click the virtual directory and choose Properties> HTTP header> MIME type. Add
Extension:. xap
MIME Type: application/x-silverlight-app
Extension:. xaml
MIME Type: application/xaml + xml
In this way, Silverlight is displayed normally.
If you call a Web Service,
And your Web Service is under the website hosting Silverlight.
This eliminates the hassle of cross-origin operations.
However, you cannot directly reference local services such as localhost.
Otherwise, it cannot be called on the server.
My method is to first deploy this service on the local IIS
Then add a service reference.
For example, the address is http: // 127.0.0.1: 8088/sl/LinqXmlService. asmx.
At this time, there is no cross-origin operation. The test is successful first.
Then open the service reference directory,
Use vs to open all the files, Ctrl + H to replace them, and select all open documents.
Replace http: // 127.0.0.1: 8088/sl/LinqXmlService. asmx
Http://www.weiqi9d.com/LinqXmlService.asmx
That is, your server address.
I don't know how to think of it. I tried it. Yes.
Another problem is that the server still cannot access. xap. I don't know why.
I just want to modify .xapto .htm and change it here.
- <param name="source" value="ClientBin/SilverlightApplication2.htm"/>
In this way, even if your sl is developed using vs2010 and the server does not have. net 4.0 installed, it can be displayed normally.
Record how Silverlight calls Web Service.
- Using System;
- Using System. Collections. Generic;
- Using System. Linq;
- Using System. Web;
- Using System. Web. Services;
-
- Namespace SilverlightApplication2.Web
- {
- /// <Summary>
- /// Summary of WebService1
- /// </Summary>
- [WebService (Namespace = "http://tempuri.org/")]
- [WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
- [System. ComponentModel. ToolboxItem (false)]
- // To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
- // [System. Web. Script. Services. ScriptService]
- Public class WebService1: System. Web. Services. WebService
- {
-
- [WebMethod]
- Public string HelloWorld ()
- {
- Return "Hello World ";
- }
- }
- }
-
- Call
- 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 );
- }
- // Create a Web Service object
- ServiceReference1.LinqXmlServiceSoapClient ws = new ServiceReference1.LinqXmlServiceSoapClient ();
- Void Page_Loaded (object sender, RoutedEventArgs e)
- {
- AddEvent ();
- Bind ();
- }
- // Register an event, which is similar to Ajax callback.
- Private void AddEvent ()
- {
- Ws. HelloWorldCompleted + = new EventHandler <ServiceReference1.HelloWorldCompletedEventArgs> (ws_HelloWorldCompleted );
- }
- // Callback function
- Void ws_HelloWorldCompleted (object sender, ServiceReference1.HelloWorldCompletedEventArgs e)
- {
- Button1.Content + = e. Result + "hi ";
- // MessageBox. Show (e. Result );
- }
- Private void Bind ()
- {
- Ws. HelloWorldAsync ();
- }
-
- }
- }
I hope to help my friends who are learning Silverlight and ask me to answer my questions.