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.