Microsoft – WCF/OData – Deploying Services to IIS
来源:互联网 发布:服务器对应默认端口 编辑:程序博客网 时间:2024/06/16 00:20
Introduction
There are a couple of paths we can take towards deploying our web services.
Prerequisite – Msdeploy
Introduction
I really enjoyed realizing the benefits of Microsoft MSDeploy. It allows us to deploy to the local server and to remote hosts, as well.
Here is a list of arguments that are supported:
Argument Meaning/TSimulates deployment/YActual deployment/MDestination Name of remote computer/UDestination user name/PDestination password/AAuthentication – NTLM/BasicVisual Studio Publishing
We can publish from Visual Studio and here are the steps to take:
- Launch Visual Studio
- Load the Project
- Access the “Solution Project”
- Select the project, make sure to select the Project and not the Solution
- Right click on your selection
- And, from the drop-down menu, select “Publish…”
Publish Web Application – Profile
The first screen upon launching “Publish Web Application” is the screen pasted below:
As we do not have existing profiles, we will access the drop-down menu and select the “New” option.
Publish Web Application – Profile
In the screen below, we have chosen the name “SoftApps”; for our Profile.
Publish Web Application – Connections
The connection method is the most important screen. It in we will choose the publish method, the service URL, and the Site/Application.
To just show how important it is, I burnt up a couple of hours, upon entering anincorrect “Site/application” in the screen below.
The right choice for “Site/application” is:
The important distinction been that the former choice has SoftAppsWCF and the corrected choice has “Default Web Site/SoftAppsWcfService“.
IIS has a default web site known as “Default Web Site”. And, you likely want to use that one. On the other hand, If you are an expert IIS Administrator, you very well might have created a new web site that you want to indicate here.
Publish Web Application – Settings
The next important screen is the “Settings” screen. In it, we choose between “debug” and “release”.
During your first iterations, I will suggest that you choose the Debug choice.
The next important decision is confirming your Database Connection Strings. Please keep in mind that if you have the “Use this connection string at runtime (update destination web.config)” checked, you may end-up over-writing previously carefully tailored DB connection profiles on targeted hosts.
Publish Web Application – Preview
The preview screen is next.
Msdeploy
Background
Pasted below is the output from *.deploy.cmd:
We unsuccessfully targeted a remote host.
wcfServiceSoftApps.deploy.cmd /T /M:WebServerRemoteSetParameters from: "WcfServiceSoftApps.SetParameters.xml"You can change IIS Application Name, Physical path, connectionStringor other deploy parameters in the above file.------------------------------------------------------- Start executing msdeploy.exe------------------------------------------------------- "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='WcfServiceSoftApps.zip' -dest:auto,computerName="WebServerRemote",includeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"WcfServiceSoftApps.SetParameters.xml" -whatifInfo: Using ID '2158a280-82ae-462d-9117-683b7c2aaf35' for connections to the remote server.Error Code: ERROR_DESTINATION_NOT_REACHABLEMore Information: Could not connect to the remote computer ("WebServerRemote"). On the remote computer, make sure that Web Deploy is installed and that the required process ("Web Deployment Agent Service") is started. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_DESTINATION_NOT_REACHABLE.Error: The remote server returned an error: (404) Not Found.Error count: 1.
… due to the error code (ERROR_DESTINATION_NOT_REACHABLE), I realized I needed to do a couple of things:
- Install & configure WebDeploy
- Configure hosts firewall rules to allow network port connections
Msdeploy Download Matrix
I think you can go with the latest version supported by your OS.
And, for most people starting from Windows XP to Windows 2008 that will be MSDeploy version 3.
VersionURLOS VersionVersion 1.1http://www.microsoft.com/en-us/download/details.aspx?id=24709 (x86)http://www.microsoft.com/en-us/download/details.aspx?id=4148 (x64)Windows 7, Windows Server 2003, Windows Server 2008, Windows Vista, Windows XPVersion 2http://www.microsoft.com/en-us/download/details.aspx?id=25230Windows 7, Windows Server 2003 Service Pack 2, Windows Server 2008, Windows Server 2008 R2 SP1, Windows Vista Service Pack 2, Windows XP Service Pack 3Version 3http://www.microsoft.com/en-us/download/details.aspx?id=30436Windows 7 Professional, Windows Server 2003 Service Pack 2, Windows Server 2008, Windows Server 2008 R2 SP1, Windows Server 2012 Release Candidate, Windows Vista, Windows XPVersion 3.5 http://www.iis.net/downloads/microsoft/web-deployDownload Msdeploy
Download the latest available MSDeploy for your deployment host. As I often say, in terms of “Enterprise” Development and Deployment roadmap, Microsoft’s train is really a high speed train. Yesterday it was called MSDeploy, Today is called WebPI, and next week it will yet be called something else.
So as I am on yesterday’s timeline, I will stay with MSdeploy and download it from http://www.microsoft.com/en-us/download/details.aspx?id=30436.
The version is v3.
As an aside and as a satire, I am trying to play music on this MS Windows 2012 box, and I do not even know how to get to MS Media Player. So what to do, but yet again Goggle for help!
Salvation came from David Trounce:
Add Feature … User Interface and Infrastructure … Desktop Experience. This is similar to Server 2008 R2.
http://social.technet.microsoft.com/Forums/windowsserver/en-US/a816bbdc-5a9c-4cf9-aa8c-090a61da3e3a/need-to-install-windows-media-player-on-windows-server-2012-release-candidate-many-apps-requires?forum=winserver8gen
… Must not be my time, as still no WMPlayer. Will just go back to Apple’e iTune, as that is installed and working.
About an hourly later, as I closed some of the multiple screens that I had left opened, discovered that I needed to restart.
This was indicated as I closed “Sever Manager”. And, noticed the information detailed below:
That might be why no WindowsMediaPlayer.
Install Msdeploy
On the targeted host, here is a sample DOS Batch script that does the following:
- It installs WebDeploy_2_10_x85_en-US.msi
- The destination port is 8080 and the targeted Virtual Directory is /MSDeployAgentService2
- And, it restarts the “Web Deployment Agent Service” (MsDepSvc)
rem msiexec /I <msi_filename> /passive ADDLOCAL=ALL LISTENURL=http://+:8080/MsDeployAgentService2/msiexec /I WebDeploy_2_10_x86_en-US.msi /passive ADDLOCAL=ALL LISTENURL=http://+:8080/MsDeployAgentService2/net stop msdepsvc /ynet start msdepsvc
Validate Msdeploy
Once the deployment package is prepared, test it out by issuing the *.deploy.cmd and passing in the /T command argument.
The *.deploy.cmd does a few important things:
- It reads the *.SetParameters.xml file and one is able to change the Web Application Name, the Physical Path, and DB ConnectionString
When I issued “WcfServiceSoftApps.deploy.cmd /T” to test out my install, I get the sampled output shown below:
SetParameters from: "WcfServiceSoftApps.SetParameters.xml"You can change IIS Application Name, Physical path, connectionStringor other deploy parameters in the above file.------------------------------------------------------- Start executing msdeploy.exe------------------------------------------------------- "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='WcfServiceSoftApps.zip' -dest:auto,includeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"WcfServiceSoftApps.SetParameters.xml" -whatifInfo: Adding directory (Default Web Site/SoftAppsWcfService\bin).Info: Adding file (Default Web Site/SoftAppsWcfService\bin\EntityFramework.dll).Info: Adding file (Default Web Site/SoftAppsWcfService\bin\Microsoft.Data.Edm.dll).Info: Adding file (Default Web Site/SoftAppsWcfService\bin\Microsoft.Data.OData.dll).Info: Adding file (Default Web Site/SoftAppsWcfService\bin\Microsoft.Data.Services.Client.dll).Info: Adding file (Default Web Site/SoftAppsWcfService\bin\Microsoft.Data.Services.dll).Info: Adding file (Default Web Site/SoftAppsWcfService\bin\System.Spatial.dll).Info: Adding file (Default Web Site/SoftAppsWcfService\bin\WcfServiceSoftApps.dll).Info: Adding file (Default Web Site/SoftAppsWcfService\ModelSoftApps.Context.tt).Info: Adding file (Default Web Site/SoftAppsWcfService\ModelSoftApps.edmx.diagram).Info: Adding file (Default Web Site/SoftAppsWcfService\ModelSoftApps.tt).Info: Adding file (Default Web Site/SoftAppsWcfService\packages.config).Info: Adding file (Default Web Site/SoftAppsWcfService\Service1.svc).Info: Adding file (Default Web Site/SoftAppsWcfService\WcfDataServiceSoftApps.svc).Info: Adding file (Default Web Site/SoftAppsWcfService\Web.config).Info: Adding ACL's for path (Default Web Site/SoftAppsWcfService)Info: Adding ACL's for path (Default Web Site/SoftAppsWcfService)Total changes: 17 (15 added, 0 deleted, 2 updated, 0 parameters changed, 4302476 bytes copied)
Actual Deploy
Actual deploy by passing in the /Y argument. To truly deploy against a host named Sunlight we will issue:
WcfServicesSoftApps.deploy.cmd /T /M:Sunlight
IIS – Backup IIS Configuration
Backup IIS Configuration
I later found out that IIS as a capable and easily accessible tool for backing up IIS Configuration.
I will say use it before mucking up IIS too much.
Sample backup invocation
%windir%\system32\inetsrv\appcmd add backup 20131123_b4WcfInstall
List backups
%windir%\system32\inetsrv\appcmd.exe list backup
List backups
I was curious as to where backups are saved and so inquisitively goggled for where.
Thankfully did not over indulge as Mike Volodarsky’s blogged about same – Most Important AppCmd Commands: Backing up and restoring IIS7 configuration – http://mvolo.com/most-important-appcmd-commands-backing-up-and-restoring-iis7-configuration/.
And, so I now that I need to do backups via appcmd and that they are stored in the C:\windows\system32\inetsrv\backup.
And, also importantly, I should occasionally back that folder up to an external storage.
IIS – Application Pool
Introduction
It is possible that this is not actually needed, but I think it is best to create or identify an appropriate Application Pool. And, then create and seed a Virtual Directory.
Create Application Pool
Before now I had stayed in the shadows of Microsoft .Net v2. And, so I know I need a new v4.0 Application pool:
Please keep in mind that there are only two available baseline Frameworks:
- .Net Framework v4.0.30319
- .Net Framework v2.0.50727
I know that Windows Communication Framework was introduced in Microsoft .Net 3.5 and so I know needed the v4.0 version.
Even the lure of an accurate blog post is not enough to lure me into digging more into the difference between the Classic and Integrated Managed Pipeline Modes. I am sure I will sooner than later run into a problem that will force me to learn.
IIS – Virtual Directory
Add a new Virtual Directory
Once you have decided on an Alias and Physical Path, please indicate as much.
But, more importantly click on the “Test Settings…”and validate your choice.
Msdeploy – Helpful Hint
Attempted MSDeploy again, by issuing “WcfServiceSoftApps.deploy.cmd /y”..
And, here is the output I received.
U:WcfServiceSoftApps.deploy.cmd /y SetParameters from:"U:\WcfServiceSoftApps.SetParameters.xml"You can change IIS Application Name, Physical path, connectionStringor other deploy parameters in the above file.------------------------------------------------------- Start executing msdeploy.exe------------------------------------------------------- "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='U:\WcfServiceSoftApps.zip' -dest:auto,inudeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtensi -setParamFile:"U:\WcfServiceSoftApps.SetParameters.xml"Error Code: ERROR_APPPOOL_VERSION_MISMATCHMore Information: The application pool that you are trying to use has the 'managedRuntimeVersion' property set to 'v2.This application requires 'v4.0'. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_APPPOOL_VERSIOMISMATCH.Error count: 1.
The important error informant is the line that read:
Error Code: ERROR_APPPOOL_VERSION_MISMATCHMore Information: The application pool that you are trying to use has the 'managedRuntimeVersion' property set to 'v2.This application requires 'v4.0'. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_APPPOOL_VERSIOMISMATCH.
Microsoft .Net Framework / OS Compatibility
I think it is important to note that you probably should think a bit about your development goals and weigh that against current deployment state. That is, which WinOS version are you currently running and which .Net Frameworks does that OS Support.
For example, if you ‘re running MS Windows 2003, it does not support .Net Framework 4.5.
This is stated as much @ .NET Framework System Requirements – .NET Framework 4.5 (http://msdn.microsoft.com/en-us/library/8z6watww(v=vs.110).aspx).
.Net Framework 4.5 can only be installed on MS Windows 2008, 2008/R2, 2012, 2012/R2.
Review & Confirm your Visual Studio Project Targeted Microsoft .Net Framework
While we are it, let us quickly and briefly confirm which .Net Framework we are targeting:
- Launch Visual Studio
- In Visual Studio, Access “Solution Explorer”
- Select the Project – Please be sure to choose the Project and not the Solution
- Right click on the Project
- From the drop-down menu, select the “Properties” entry
- On the left side of the window, move up and select the “Application” tab
- The “Target Framework” choices are availed, please review and confirm that this is the actual Framework you will like to target
IIS Manager – Review & Change CLR Version
Accessed IIS Manager and fumbled quite a bit with changing the targeted CLR version.
Even though I had accessed the Advanced configuration panel:
There was still no obvious path to changing the CLR Version.
Thought a bit more, and decided to change from a simple Virtual Directory to an Actual Application.
To do so:
- Select the Virtual Directory
- Right click on your selection and from the drop-down menu select “Convert to Application”
Select “Convert to Application” from drop-down menu
Add Application screen
Here is the initial “Add Application” screen:
Application Pool 2.0 Screen
Here is the default “Application Pool” screen:
It is obviously referencing “.Net Framework version: 2.0”.
Application Pool 4.0 Screen
Here is us changing to our preferred custom 4.0 pool.
Test Settings
Here is what our screen looks like, once we have the Application Pool that we want.
Test Settings
Please make sure to Test things out – Just click on “Test Settings…”.
Click Close.
And, once you are good “Click OK” and let us see…
Msdeploy – Good!
Attempted MSDeploy again, by issuing “WcfServiceSoftApps.deploy.cmd /y”..
And, here is the output I received.
IIS – Virtual Directory Configuration
Introduction
I spent the whole day trying to get this application to work.
For those who feel the same struggle, here are screen shots from a working version.
Connection Strings
Authentication
Directory Browsing
Failed Request Tracing Rules
Logging
The important configuration items to note are:
FeatureWhy important?Connection StringsLists DB Connection itemsAuthenticationThe ones we have enabled are Anonymous / Asp.Net / Basic / WindowsDirectory BrowsingEnabled – To list individual files – Should be disabled once you have things working wellFailed Request Tracing FilesAs I said I experienced quite a bit of hardship and so resorted to this to try and see what was wrongLoggingWill talk more about this in a later postError
Error: The server was unable to process the request due to an internal error.
You might get the error pasted above, if you do not add a couple of code snippets to your source code.
You need this class decoration statement:
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
And, in your class initializeService method, you need:
//very important as otherwise you will get the very unhelpful //The server encountered an error processing the request. //See server logs for more details. //use Verbose Errors config.UseVerboseErrors = true;
Our new source code reads:
using System;using System.Collections.Generic;using System.Data.Services;using System.Data.Services.Common;using System.Linq;using System.ServiceModel.Web;using System.Web;namespace WcfServiceSoftApps{ //public class WcfDataServiceSoftApps : DataService //< /* TODO: put your data source class name here */ > [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)] public class WcfDataServiceSoftApps : DataService< SoftAppsEntities> { // This method is called only once to initialize service-wide policies. public static void InitializeService(DataServiceConfiguration config) { config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; //very important as otherwise you will get the very unhelpful //The server encountered an error processing the request. //See server logs for more details. //use Verbose Errors config.UseVerboseErrors = true; config.SetEntitySetAccessRule("*", EntitySetRights.All); config.SetServiceOperationAccessRule( "ApplicationListFetchAll" , ServiceOperationRights.All ); config.SetServiceOperationAccessRule( "ApplicationListFetchFiltered" , ServiceOperationRights.All ); } [WebGet] public IQueryable ApplicationListFetchAll() { return this.CurrentDataSource.usp_GetApplicationList_Filtered (null, null, null, null, null).AsQueryable(); } [WebGet] public IQueryable ApplicationListFetchFiltered ( Guid? ApplicationTypeID , Guid? VendorID , Guid? LicensingID , short? PlatformID , String SearchTag ) { return this.CurrentDataSource.usp_GetApplicationList_Filtered ( ApplicationTypeID, VendorID, LicensingID, PlatformID, SearchTag ).AsQueryable(); } } // ApplicationListFetchFiltered}
IIS – Configuration – Error – 0x80070002
Once I added the debug statements, ran into a prescient error.
This error pointed me to the fact that I had stipulated for .Net Framework 4.5
IIS – Configuration – Error – 0x80070002
Thought everything is well. But, stayed in the wilderness for most of my day. The exact error message is.
Item ValueErrorHTTP Error – 404.0 – Not FoundModuleIIS Web CoreNotificationMapRequestHandlerHandlerStaticFileError Code0x80070002HTTP Error 404
Solution:
On a MS Windows 2012
Download & Install Microsoft .Net 4.5
As my installed MS Visual Studio 2012 was configured to point at Microsoft .Net 4.5 I needed to upgrade from v4.0 to v4.5.
- Microsoft .NET Framework 4.5
http://www.microsoft.com/en-us/download/details.aspx?id=30653
Install it
Install it
Configure Microsoft WCF – ServiceModelReg.exe
C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe –i
Configure Microsoft WCF Services – HTTP Activation
- Launch Control Panel \ Programs and Features
- Access “Windows Features”
- In the “Select Install Type ” – Role based or Featured-based installation
- In the “Select destination server” – Select a server from the server pool
- In the “Feature roles” – Make sure that “.Net Framework 3.5 Features is installed” — “.Net Framework 3.5 Features” and “HTTP Activation” and “Non-HTTP Activation”
- In the “Feature roles” – Make sure that “.Net Framework 4.5 Features is installed” — “.Net Framework 4.0/4.5 Features” and “WCF Services – HTTP Activation” / “WCF Services – TCP Activation” / “WCF Services – TCP Port Sharing”
Summary:
Aforementioned, I spent a whole day trying to get this to work. I wish that I can say that using this or that tool gave me specific error messages per MS Windows 2012.
Yes, I know that I was having “Microsoft WCF Service – HTTP Activation” problem.
As I struggled a bit and Googled for help, I found out that I should pay more attention to my targeted Framework.
But, the time wasted was more with properly provisioning WCF for .Net 4.0/4.5. I assumed that the one for v3.5 will suffice; and had a blind spot to the need for checking the v4.0/v4.5 package(s), as well.
All problems stayed same until I goggled specifically for MS Windows 2012 & WCF. And, found a fellow WordPresser – Steve – Host WCF in IIS8 – Windows Server 2012 ( http://3water.wordpress.com/2012/09/05/host-wcf-in-iis8-windows-server-2012/ ).
His guidance along proper configuration of Microsoft .Net v4.0 on a MS Windows 2012 finally brought me across the line.
References:
References – IIS
- If you’re deploying a WCF Web API application to your IIS 7.x you might receive a HTTP Error 404.0 (MapRequestHandler / StaticFile)http://blog.alexonasp.net/post/2011/12/11/HTTP-Error-4040-Not-Found-(MapRequestHandler-StaticFile)-when-deploying-WCF-Web-API-on-IIS-7x.aspx
- Error message after you install the .NET Framework 4.0: “Could not load type ‘System.ServiceModel.Activation.HttpModule'”
http://support.microsoft.com/kb/2015129 - IIS 7.0 – HTTP Error 404.17 – Not Found – Static File Handler
http://forums.iis.net/t/1160143.aspx
References – IIS – Error Logging
- Troubleshoots – Using failed request tracing – Troubleshooting failure requests using Tracing in IIS
http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis
References – IIS – WCF – MS Windows 2012
- Host WCF in IIS8 (Windows Server 2012)
http://3water.wordpress.com/2012/09/05/host-wcf-in-iis8-windows-server-2012/
References – IIS – appcmd
- Getting Start with iis – Getting started with appcmd.exe
http://www.iis.net/learn/get-started/getting-started-with-iis/getting-started-with-appcmdexe#Managing
- Most important appcmd commands – backing up and restoring iis7 configuration
http://mvolo.com/most-important-appcmd-commands-backing-up-and-restoring-iis7-configuration/
References – Debugging WCF Services
- Turn on IncludeExceptionDetailInFaults while connecting to a WCF service from a client
http://blogs.msdn.com/b/paraswadehra/archive/2011/01/07/turn-on-includeexceptiondetailinfaults-while-connecting-to-a-wcf-service-from-a-client.aspx
- Microsoft – WCF/OData – Deploying Services to IIS
- Getting Started with igGrid, OData, and WCF Data Services
- OData v3与WCF Data Services 5.x简介
- How to bind the odata services to SAP ui5 table
- WCF4.0 –- RESTful WCF Services
- WCF4.0 –- RESTful WCF Services
- WCF Data Services and jQuery(自建grid以odata显示)
- 在控制台应用程序中使用 OData 源(WCF Data Services 快速入门) 示例
- Deploying Network Services
- WCF托管在IIS、Windows Services下的性能对比
- odata mvc wcf调用方法
- WCF4.0 –- RESTful WCF Services (1) (入门)
- WCF4.0 –- RESTful WCF Services (3) (Raw Stream)
- WCF4.0 –- RESTful WCF Services (4) (Basic Security)
- WCF4.0 –- RESTful WCF Services (5) (缓存)
- WCF4.0 –- RESTful WCF Services (1) (入门)
- WCF4.0 –- RESTful WCF Services (3) (Raw Stream)
- WCF4.0 –- RESTful WCF Services (4) (Basic Security)
- 消息中间件 AMQP协议 核心概念及原理
- 2017 东华校赛
- 反射获取构造方法并使用
- book_effective Python_59个有效办法(一)
- 双向dfs求强连通分量
- Microsoft – WCF/OData – Deploying Services to IIS
- Android初学者的简单登录,利用外形资源和selector选择器
- 好玩的分词——python jieba分词模块的基本用法
- 特征选择-卡方检验用于特征选择
- 基于GUI的AWT,Swing写的一个餐厅点菜系统
- Golang -- 互斥锁
- 217. Contains Duplicate(疑问待解答)
- mysql之 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 11
- 反反爬虫------设置scrapy随机user_agents