[WCF Study Notes] My WCF journey (1): create a simple WCF program, and use the wcf Study Notes
I recently learned about WCF and found a lot of information. Finally, I found this good series of Artech. I hope I can make some gains.
This article is used to record various basic problems encountered in the process of learning and practicing WCF and its solutions for future review. These problems may be very basic, but it is sometimes difficult for new users to find a solution without experience. These problems have really plagued me for some time. It is my pleasure to use it for other new users.
Blog series address: My WCF journey blog series Summary
My WCF journey (1): create a simple WCF Program
1.After the first simple WCF program is developed and run (set the Hosting project as the startup Item),Host. Open (); "Encountered the following error
"HTTP cannot register URL http: // +: 3721/calculatorservice /. The process does not have access to this namespace (for more information, see http://go.microsoft.com/fwlink? LinkId = 70353 )."
As I mentioned in other articles before, I guess how to solve it:Run Visual Studio as an administrator.. As for the reason, I did not go into detail.
2. How do I select Service Type when adding a Service in the WCF Service Configuration Editor?
I would have liked to use the Tool by hand, but I saw this Tool for the first time and wanted to play it. As a result, the Service Type was canceled when I created the Service!
Do you still remember that there is such a section in the configuration using code? ServiceHost host = new ServiceHost (typeof (CalculatorService ))
Yes, Service Type is the implementation Type of our custom Service, but we need to specify a fully qualified name, as shown in Artech In the example. wcfServices. services. calculatorService, which is applied to the configuration file as the name attribute of the Service element, that is, <service name = "Artech. wcfServices. services. calculatorService ">
After the selection is complete, you have to select the Contract Type of Endpoint. the same method as above can be seen in the code.
There are other options and settings. After the configuration, I decided to no longer use this Tool. It was a waste of time and energy. It was so painful. Haha, let's just be honest.
3. How to add a service reference? When hosting.exe is run, an error is reported?
As mentioned in step 5 (creating a client to call the service:When running the Service boarding program (hosting.exe), right-click the Client project and choose Add Service References from the context menu )".
Run hosting.exe, so it is not in Debug mode. In Debug mode, you cannot add service references to the project. The correct method is to find the hosting.exe generated after compilation in the Bin/Debug or Bin/releasefolder of the physical path of the Hosting project, and run it as an administrator (Note: if you do not run it as an administrator, an error is reported ).
4. When IIS is hosted, the following error occurs during URL access:HTTP 500.19-Internal Server Error
Configuration error: unable to read the configuration file due to insufficient Permissions
Solution: Add IIS_IUSRS permissions to the virtual directory.
5. When IIS is hosted, an error is reported during URL access.
The "WcfServices. Services. CalculatorService" type cannot be found. It is provided as the Service feature value in the ServiceHost command, or in the configuration element system. serviceModel/serviceHostingEnvironment/serviceActivations.
Note:An unhandled exception occurred during the execution of the current Web request. Check the stack trace information for details about the error and the source of the error in the code.
Exception details:System. InvalidOperationException: The type "WcfServices. Services. CalculatorService" cannot be found. It is provided as the Service feature value in the ServiceHost command, or in the configuration element system. serviceModel/serviceHostingEnvironment/serviceActivations.
Solution: Copy Services. dll and Contracts. dll from the Bin/Debug | Release directory to the Bin directory, or change the Output path to Bin \ in the Project Build option and re-compile.This teacher mentioned in the article, but did not explain what the error will be. If you accidentally neglect it, it is not easy to tell from this error message what the cause is.
There are some other problems, such as forgetting to record them. So far, it took a lot of time to complete this exercise. It seems that the road is still long.
TT