For the first time, I read two articles about the conceptArticleYou can manually enter a simple logProgramIs a data table, which can record the work done from time to time on a specific day. The company requires that the data be filled in every day. The program structure is as follows:
Server:
- Foolish. CMIS. Service
- Foolish. CMIS. wcfhost
Client:
The procedure is as follows:
- Create a new WCF project named foolish. CMIS. Service, and define a Service Interface
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. runtime. serialization; Using System. servicemodel; Using System. text; Namespace Foolish. CMIS. Service {[servicecontract] Public Interface Iworklogservice {[operationcontract] list <lm_worklog> getworklog (datetime astartdate, datetime aenddate, String Alogtype, String Auserid); [operationcontract] lm_worklog saveworklog (lm_worklog worklog); [operationcontract] Void Deleteworklog (lm_worklog worklog); [operationcontract] Bool Islogin ( String Username, String Password );}}
2. Implement the interface and use LINQ. Therefore, it is easy to implement database access. Configure the interface and drag the table.
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. runtime. serialization; Using System. servicemodel; Using System. text; Using System. runtime. interopservices; Namespace Foolish. CMIS. Service { Public Class Worklogservice: iworklogservice {[dllimport (" Libpasschk. dll ")] Public Static Extern Boolean isvalidpassword (string apass, string apassencoded ); Public List <lm_worklog> getworklog (datetime astartdate, datetime aenddate, String Alogtype, String Auserid) {businessdataclassesdatacontext DB = New Businessdataclassesdatacontext ();If (Alogtype. Equals ("") {var query = from WL In DB. lm_worklogswhere (WL. fillpeople = auserid) & (WL. logdate <aenddate) & (WL. logdate> astartdate) orderby WL. logdate descendingselect Wl; Return Query. tolist <lm_worklog> ();} Else {Var query = from WL In DB. lm_worklogswhere WL. fillpeople = auserid & WL. logdate <aenddate & WL. logdate> astartdate & WL. guide_id = alogtypeselect Wl; Return Query. tolist <lm_worklog> () ;}# region iworklogservice Public Lm_worklog saveworklog (lm_worklog worklog) {businessdataclassesdatacontext DB = New Businessdataclassesdatacontext (); If (Worklog. log_id.equals ("") {dB. lm_worklogs.insertonsubmit (worklog );} Else {DB. lm_worklogs.attach (worklog, True );} DB. submitchanges (); Return Worklog;} # endregion # region iworklogservice Public Void Deleteworklog (lm_worklog worklog) {businessdataclassesdatacontext DB = New Businessdataclassesdatacontext (); DB. lm_worklogs.attach (worklog,True ); DB. lm_worklogs.deleteonsubmit (worklog); DB. submitchanges () ;}# endregion # region iworklogservice Public Bool Islogin ( String Username, String Password) {userinfodataclassesdatacontext userdb = New Userinfodataclassesdatacontext (); ienumerable < String > Userpassqry = from orgatt In Userdb. torgattributeswhere orgatt. FID =" Password "& (From pSN In Userdb. tpersons where PSN. FID = username select PSN. fguid). Contains (orgatt. fguid) Select orgatt. fvalue; Foreach ( String Userpass In Userpassqry ){ Return Isvalidpassword (password, userpass );} Return False ;} # Endregion }}
This simple service is implemented.
3. Create a web project and reference foolish. CMIS. the service is actually a WCF Service that finds IIS as the host, note that you need to copy the database connection and WCF configuration files in the WCF Service configuration file to webconfig, and change wshttpbinding to basichttpbinding, since wcf cf only supports the basichttpbinding and windowsmobilemailbinding methods, you must add <servicemetadata httpgetenabled = "true"/> to enable access to netcfsvcutil.exe. Create a new file worklog. SVC with the following content:
<% @ Servicehost Language ="C #"DEBUG ="True"Service ="Foolish. CMIS. Service. worklogservice"%>
OK, the service and hosting are both successful, and the server has been completed. Now you can enter http: \ localhost \ worklog. SVC in the browser to test.
4. First, use netcfsvcutil.exe to generate someCode
Netcfsvcutil.exe http: \ localhost \ worklog. SVC
Note that we should close vs in this step as much as possible. I always report errors without turning it off and take a lot of detours.
Two files cfclientbase. CS/worklogservice. CS are generated. It is okay to create a new smart device project and introduce these two files.
The following is the code for using the WCF Service. I copied the code of fox23.
System. servicemodel. channels. Binding binding = worklogserviceclient. createdefaultbinding ();StringRemoteaddress = worklogserviceclient. endpointaddress. Uri. tostring (); endpointaddress endpoint =NewEndpointaddress (remoteaddress); worklogserviceclient client =NewWorklogserviceclient (binding, endpoint); loglist = client. getworklog (startdate, enddate, "", txtusername. Text );
A simple four-step application is complete. After my P800 is connected to the PC, the test is normal. However, an error is reported when mobile WAP is used to access the Internet. The following are two questions that I am confused about:
(In fact, I write so much, that is, to hopefully mix it on the homepage, so that the ox may be able to see my problem. It is written in a sequential billing method, polluting everyone's eyes, sorry, haha .)
The error is as follows:
The content type of the Response Message application/vnd. WAP. wmlc; charset = UTF-8 does not match the bound content type (text/XML; chartset = UTF-8. If you use a custom encoder,
Make sure that the iscontexttypesupported method is correctly implemented.
I searched the internet and did not find any similar issues. So I can only publish them here to see if anyone knows how to solve them.
My thoughts are as follows:
1. How to Use netcfsvcutil to specify the binding content of the generated message as application/vnd. WAP. wmlc? If this format is generated, it cannot be serialized.
2,I searched the internet for a long time and did not find an introduction to the iscontexttypesupported method. I don't know how to implement the item reform.
I think the second possible solution is to solve the problem.
Power by SSS