Integration of SilverLight2.0 DataService WCF

Source: Internet
Author: User

Topics:

1. Is it appropriate for WCF and DataService to be used together?

2. DataService authentication Exception?

 

1. Is it appropriate for WCF and DataService to be used together?

When creating a DataService, an item is automatically configured in web. config:

<ServiceHostingEnvironment aspNetCompatibilityEnabled = "true"/>

When WCF and DataService coexist, a poor phenomenon occurs. Look at this picture, what is it, there is no good activation service,

Oh, no. No. No. WCF cannot run normally;

Why? Is it because of the above configuration item?

In fact, the WCF Service can be concurrently hosted with ASP. NET in IIS, or in compatibility mode. The default configuration is concurrent with ASP. NET.

The requests of the WCF Service are received by the ASP. NET runtime, but they are not involved in the processing of these requests. During a working process, the WCF runtime detects incoming requests and processes them through the WCF stack.

When ASP. NET and WCF work in parallel, some side effects need to be noticed. For example, you cannot define an access control list for SVC resources, and in this context, more importantly, HttpContext when you access resources from within the WCF Service. the Current attribute always returns null. Therefore, for the WCF Service, you cannot obtain any information about ASP. NET login users.

Generally, the WCF model is designed to be applicable to both the bearer environment and the transmission mechanism. However, to meet the security requirements of the AJAX service layer, more strict collaboration must be implemented between the WCF and the ASP. NET environment. This is exactly the problem to be solved in the ASP. NET compatibility mode of WCF.

When running in compatible mode, the WCF Service is fully involved in the lifecycle of ASP. NET requests. The actual result is that the WCF Service has the right to access the same information as the ASMX Web service. This will support file-based authorization, and more importantly, HttpContext. Current has been correctly set.

Compatibility mode is the global settings enabled at the application level. However, various services can reject or accept this mode. To enable the compatibility mode, enter the following part in the configuration file:

<system.serviceModel><serviceHostingEnvironment aspNetCompatibilityEnabled="true" /></system.serviceModel>

Each service declares its support for the compatibility mode through the RequirementsMode attribute of the AspNetCompatibilityRequirements attribute (which will be set for the service class rather than the Convention. The value of this attribute is Required, Allowed, and NotAllowed. The default value isNotAllowedThis means that the RequirementsMode attribute must be changedAllowedOrRequired.

You can see it here. How is Code implemented? :)

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]public class Service : IService{。。。。}
Look at the results. Nice
AboutSuitableIs there any other topic ?! Who knows, who follows the post :)
 
 
2. DataService authentication Exception?
Exception. Oh, it's another exception, a yellow page ..

In fact, the solution is simple, three steps

Listen To Me

Step 1: Ctrl + R then Input Inetmgr

Step 2: unChecked anonymous visit

Step 3: return current project and Redo Create Virtual Directory (this Step is important. Remember it)

Step 2

Step 3

Oh, let's see what it is. The result is that the service O is ready. Sleeping. :)

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.