Summary of cross-origin Silverlight calls

Source: Internet
Author: User
Tags silverlight

I recently installed a vs2008 program to study Silverlight (SL) and WCF. I found that calling a previously released WCF has never been successful and an error message HTTP is returned: // localhost/mywcfservice/service2.svc do not allow cross-origin access. my SL access path is http: // localhost: 8457/silverlightapplication3.web/silverlightapplication3testpage. aspx #/home. the WCF domain is http: // localhost. The default port of IIS is 80, http: // localhost: 80, and http: // localhost: 8457 is obviously two different domains. Then, he began his journey to Baidu habitually. I checked a lot of information and read many posts, all of which are about cross-origin access. By default, Sl does not allow cross-origin access to WCF. If cross-origin access is required, you must configure a cross-origin policy. XML, the content is as follows<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <access-Policy> <br/> <cross-domain-access> <br/> <Policy> <br/> <allow-from http-request-headers = "*"> <br/> <domain uri = "*"/> <br/> </allow-from> <br/> <grant-to> <br/> <resource Path = "/" include-subpaths = "true"/> <br/> </grant-to> <br/> </Policy> <br/> </Cross-Domain-access> <br/> </access-Policy>So many people will ask: where is this file stored? This file must be placed in the root directory of IIS, rather than the virtual directory of your SL website. For example, the root directory of your IIS is usually C:/inetpub/wwwroot, and the virtual directory of your website may be D:/testwebsite. This file must be placed in C: /inetpub/wwwroot instead of the latter, this is the first place to pay attention.

At this time, the cross-origin policy has been configured, And the principle should be able to access WCF, but still reports the error: Remote Server Error: Not found. Brother was shocked at the time, and then used the fiddler software to track Web requests and responses. He found that requests were sent and the request address was correct, but the following error occurred: HTTP/1.1 415 cannot process the message because the content type 'application/soap + msbin1' was not the expected type 'application/soap + XML; charset = UTF-8 '. then I went on to check the information on the Internet. Many of them are from e-files, in the following code, we can see that the binding of the server end point is inconsistent with the binding of the client end point. Then I checked it carefully, I found that the binding of the final point of the WCF Service released by my server is wshttpbinding, while the binding configured for the SL client proxy class is custombinding, which is indeed inconsistent, however, it seems that the sl3.0 client configuration does not support W Shttpbinding seems to support only custombinding and basichttpbinding, so I changed the binding of both the server and client to basichttpbinding, then re-released the server, updated the client service reference, ran the SL program, and called the WCF Service, success !! The problem that plagued me for a day turned out to be so simple. I hope it will be helpful to people who have just come into contact with me in this field.

Configure servicereferences. clientconfig on the SL client as follows:<Configuration> <br/> <system. servicemodel> <br/> <bindings> <br/> <basichttpbinding> <br/> <binding name = "bhbs2" maxbuffersize = "2147483647" maxcompute edmessagesize = "2147483647"> <br /> <security mode = "NONE"/> <br/> </binding> <br/> </basichttpbinding> </P> <p> </bindings> <br /> <client> </P> <p> <endpoint address = "http: // localhost/mywcfservice/service2.svc "<br/> binding =" basichttpbinding "bindingconfiguration =" bhbs2 "Contract =" servicereference1.iservice2 "<br/> name =" bhbs2 "/> <br /> </client> <br/> </system. servicemodel> <br/> </configuration> <br/>, Http: // localhost/mywcfservice/service2.svc is the address of the WCF Service that I published on IIS.

 

The configuration of the WCF server is as follows:<System. servicemodel> <br/> <services> </P> <p> <service behaviorconfiguration = "wcfservice1.service1behavior" <br/> name = "wcfservicelibrary2.service2"> <br/> <endpoint binding = "basichttpbinding" bindingconfiguration = "" <br/> name = "bhbs2" Contract = "wcfservicelibrary2.iservice2"/> <br/> </service> <br/> </services> <br/> <behaviors> <br/> <servicebehaviors> <br/> <behavior name = "wcfservice1.service2behavior"> <br/> <servicemetadata httpgetenabled = "true"/> <br/> <servicedebug includeexceptiondetailinfaults = "false"/> <br/> </behavior> <br/> </servicebehaviors> <br/> </behaviors> <br/> </system. servicemodel>

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.