After the Silverlight + WCF program is released to IIS, the client fails to access the database.

Source: Internet
Author: User
When writing a Silverlight program, we usually need to use WCF to access our backend database. It is normal to access the database during development, however, after you publish the entire silverlight project together with WCF to IIS, you will encounter the following problem: You can access the database normally on the hostIIS server, but when you use the client

When writing a Silverlight program, we usually need to use WCF to access our backend database. It is normal to access the database during development, however, after you publish the entire silverlight project together with WCF to IIS, you will encounter the following problem: You can access the database normally on the host IIS server, but when you use the client

When writing a Silverlight program, we usually need to use WCF to access our backend database. It is normal to access the database during development, however, after you publish the entire silverlight project together with WCF to IIS, you will encounter the following problem: You can access the database normally on the host IIS server, however, when a program is executed through the client, the database cannot be accessed, and there is no error message. The call page is normal.

Many people may have encountered this problem. There are also many solutions to this problem on the Internet, but most of them solve this problem from the perspective of cross-origin access, then try to add clientaccesspolicy. xml and crossdomain. after the xml configuration files and the MIME configuration in IIS are added, many people still haven't solved the problem. I am one of them. I spent some time studying the principles of WCF, finally, I re-checked the configuration of the WCF and changed the method of binding and calling the WCF, so that the problem can be completely solved. I will share with you the specific steps below.

Check your ServiceReferences. ClientConfig file. This file is automatically generated when you add a service reference to the Silverlight program. Check whether the method of binding to WCF is BasicHttpBinding. The Code is as follows:

     
          
               
                    
                         
                      
                 
            
           
               
            
       
  
 


Find the Web under your web project. in the config file, check the WCF configuration information. Check whether the binding method is "basicHttpBinding" and whether the contract name is correct. The specific code is as follows:

    
         
              
                   
                        
                         
                         
                     
                
           
          
              
                   
                        
                     
                
           
          
          
              
                   
                    
                
           
      
 


Finally, modify the code for calling WebService:

            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);            binding.MaxReceivedMessageSize = int.MaxValue;            binding.MaxBufferSize = int.MaxValue;            GxptServiceReference.Gxpt_ServiceClient client = new GxptServiceReference.Gxpt_ServiceClient(binding, new EndpointAddress(                new Uri(Application.Current.Host.Source, "../Gxpt_Service.svc")));            client.GetDataAsync();            client.GetDataCompleted += new EventHandler
 
  (client_GetDataCompleted);
 

OK. You can re-compile and release it. Do not forget to add the required clientaccesspolicy. xml and crossdomain. xml files. Otherwise, you will not be able to access WCF through IP addresses.

I hope you can solve your troubles for several days.

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.