How to deploy Silverlight and Web Service

Source: Internet
Author: User

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.

 
 
  1. <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.

 
 
  1. Using System;
  2. Using System. Collections. Generic;
  3. Using System. Linq;
  4. Using System. Web;
  5. Using System. Web. Services;
  6.  
  7. Namespace SilverlightApplication2.Web
  8. {
  9. /// <Summary>
  10. /// Summary of WebService1
  11. /// </Summary>
  12. [WebService (Namespace = "http://tempuri.org/")]
  13. [WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
  14. [System. ComponentModel. ToolboxItem (false)]
  15. // To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
  16. // [System. Web. Script. Services. ScriptService]
  17. Public class WebService1: System. Web. Services. WebService
  18. {
  19.  
  20. [WebMethod]
  21. Public string HelloWorld ()
  22. {
  23. Return "Hello World ";
  24. }
  25. }
  26. }
  27.  
  28. Call
  29. Using System;
  30. Using System. Collections. Generic;
  31. Using System. Linq;
  32. Using System. Net;
  33. Using System. Windows;
  34. Using System. Windows. Controls;
  35. Using System. Windows. Documents;
  36. Using System. Windows. Input;
  37. Using System. Windows. Media;
  38. Using System. Windows. Media. Animation;
  39. Using System. Windows. Shapes;
  40.  
  41. Namespace SilverlightApplication2
  42. {
  43. Public partial class MainPage: UserControl
  44. {
  45. Public MainPage ()
  46. {
  47. InitializeComponent ();
  48. This. Loaded + = new RoutedEventHandler (Page_Loaded );
  49. }
  50. // Create a Web Service object
  51. ServiceReference1.LinqXmlServiceSoapClient ws = new ServiceReference1.LinqXmlServiceSoapClient ();
  52. Void Page_Loaded (object sender, RoutedEventArgs e)
  53. {
  54. AddEvent ();
  55. Bind ();
  56. }
  57. // Register an event, which is similar to Ajax callback.
  58. Private void AddEvent ()
  59. {
  60. Ws. HelloWorldCompleted + = new EventHandler <ServiceReference1.HelloWorldCompletedEventArgs> (ws_HelloWorldCompleted );
  61. }
  62. // Callback function
  63. Void ws_HelloWorldCompleted (object sender, ServiceReference1.HelloWorldCompletedEventArgs e)
  64. {
  65. Button1.Content + = e. Result + "hi ";
  66. // MessageBox. Show (e. Result );
  67. }
  68. Private void Bind ()
  69. {
  70. Ws. HelloWorldAsync ();
  71. }
  72.  
  73. }
  74. }

I hope to help my friends who are learning Silverlight and ask me to answer my questions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.