Friends who have developed a Silverlight application may encounter the following problems:
When using WCF or ws for database operations, a clear service address is required. If it is WCF, It is the SVC file address. Beginners usually use the add service reference of Vs to add references directly. This is indeed a very convenient method, but what kind of troubles will this cause?
First, once the directory structure of the WS file is changed in the development phase, the WS address in the SL project must be changed. This change is not as simple as simply updating service reference, because the address has changed, you must delete the old reference to add a new reference.
Second, the problem arises when the project is fully developed and needs to be deployed on the server. If you use the add service reference of Vs to add reference during development, the system automatically generates a servicereferences. the clientconfig configuration file records the WS address, cache, connection duration, and other information. The configuration file is packaged into the xap file together with the SL project, that is to say, once the project is deployed on the server, the WS address cannot be changed. This has a very negative impact on project migration and Server IP address changes.
Here we introduce a method for dynamically obtaining ws addresses. This method does not depend on the servicereferences. clientconfig file. Although it does not depend on the configuration file, the developer still needs to use the add service reference of Vs to add a reference for generating operations on the SL end.Code. Now, go to the topic. The following is the class used to generate wsclient.
public class serviceutil
{< br> Public static string svcpath {set; get ;}
///
// get data service path
///
// path
Public static workflowserviceclient getdynamicclient ()
{< br> If (svcpath = NULL)
throw new exception ("wrong SVC path! ");
Basichttpbinding binding = new basichttpbinding (application. Current. Host. Source. scheme. Equals ("HTTPS", stringcomparison. invariantcultureignorecase )? Basichttpsecuritymode. Transport: basichttpsecuritymode. None );
Binding. maxcompute edmessagesize = int. maxvalue;
Binding. maxbuffersize = int. maxvalue;
Return new workflowserviceclient (binding, new endpointaddress (New uri (application. Current. Host. Source, svcpath )));
}
}
The above serviceutil class has a static string variable used to save the WS file path; then the following getdynamicclient method combines the host website URI of the SL application with the WS file path to form a complete ws Reference URL. The static variable svcpath is usually assigned a value before the WS operation, and the specific value can be obtained through the web site. the field in the parameter etting In the config file is passed in. As for how to obtain the parameters of the ASPX page in the SL project, I wrote it in the previous article. You can refer to it.
Http://www.cnblogs.com/kurokawa/archive/2009/11/23/1608808.html