2011-04-16 61 views
2

我在.NET Framework 3.5中有一個asmx服務,現在我已經轉換爲.NET Framework 4.0。現在我想以相同的ASMX擴展名將WCF服務作爲WCF服務運行。我閱讀了幾個有步驟的步驟來轉換它們的博客。但是,它們都是指.NET Framework 3.5。這裏是我從互聯網上獲得的參考資料。ASMX到WCF轉換

我想這和他們與3.5框架,但不能與4.0的框架工作。我得到了錯誤

無法轉換 類型的對象System.Web.Compilation.BuildResultCustomString「 鍵入 「System.Web.Compilation.BuildResultCompiledType」。

我在其上添加了httpHandler部分並且它消失了。不過現在我得到一個新的錯誤

未能加載類型 'System.ServiceModel.Activation.HttpHandler' 從程序集「System.ServiceModel, 版本= 4.0.0.0,文化=中立, 公鑰= b77a5c561934e089 '

任何人都可以幫我解決這個錯誤。

+0

我有一個框架 3.5 WCF服務與asmx擴展工作得很好。只是我將項目從3.5轉換到4.0,它相應地修改了web.config。我做了上面指定的必要更改,但是給出了錯誤。你能幫我嗎。 – Ashish 2011-04-16 12:11:10

回答

1

我想你可能需要在IIS中正確註冊.NET 4處理程序。從.NET 4框架目錄運行ServiceModelReg.exe -ia,看看它是否有幫助。

C:\Windows\Microsoft.NET\Framework\v4.0.30319>ServiceModelReg.exe /? 
Microsoft (R) WCF/WF registration tool version 4.0.0.0 
Copyright (c) Microsoft Corporation. All rights reserved. 

Administration utility that manages the installation and uninstallation of 
WCF and WF components on a single machine. 

Usage: 
    ServiceModelReg.exe [(-ia|-ua|-r)|((-i|-u) -c:<command>)] [-v|-q] [-nologo] 
[-h] 
    -ia 
    Install all components 
    -ua 
    Uninstall all components 
    -r 
    Extended only. Repairs all components 
    -i 
    Install components specified with -c 
    -u 
    Uninstall components specified with -c 
    -c:<component> 
    Install/uninstall a component: 
     httpnamespace  - HTTP namespace reservation 
     tcpportsharing  - TCP port sharing service 
     tcpactivation  - TCP activation service (unsupported on .NET 4 Clien 
t Profile) 
     namedpipeactivation - Named pipe activation service (unsupported on .NET 
4 Client Profile) 
     msmqactivation  - MSMQ activation service (unsupported on .NET 4 Clie 
nt Profile) 
     etw     - ETW event tracing manifests (Windows Vista or later 
) 
    Can be used to install several components at the same time 
    -q 
    Quiet mode (only error logging) 
    -v 
    Verbose mode 
    -nologo 
    Suppress the copyright and banner message 
    -h 
    Displays this help text. 

Examples: 
    ServiceModelReg.exe -ia 
     Installs all components 
    ServiceModelReg.exe -i -c:httpnamespace -c:etw 
     Installs HTTP namespace reservation and ETW manifest 
    ServiceModelReg.exe -u -c:etw 
     Uninstalls ETW manifests 
    ServiceModelReg.exe -r 
     Repairs an extended install 
+0

我試圖在IIS中註冊.NET 4處理程序。我運行命令 'ServiceModelReg.exe -ia' 並且它給了我警告 '[警告] HTTP命名空間保留已經存在。' 我試圖 以取消註冊.NET 4處理器'ServiceModelReg.exe -ua' 和我'檢測【警告】Windows通訊基礎的先前版本的警告 。該HTTP命名空間保留不removed.' 註冊處理再次給了我同樣的警告 '[警示]的HTTP命名空間保留已exists.' – Ashish 2011-04-17 02:41:58

+0

,實際上是期待 - 因爲它沒有它不刪除命名空間預留想要打破.NET 3 WCF,這也是你已經安裝的。忽略這些警告。你的問題現在解決了嗎? – 2011-04-17 03:07:26

+0

不,它仍然是一樣的 – Ashish 2011-04-17 10:15:32

4

我得到了它與aspNetCompatibilityEnabled工作設置爲 '真' 是這樣的:

添加一個參考:

System.ServiceModel.Activation 
在你的web.config

<system.web> 
<compilation debug="true" targetFramework="4.0"> 
    <buildProviders> 
    <remove extension=".asmx"/> 
    <add extension=".asmx" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 
    </buildProviders> 
</compilation> 
</system.web> 

<system.webServer> 
<handlers> 
    <remove name="WebServiceHandlerFactory-Integrated"/> 
    <add name="MyNewAsmxHandler" path="*.asmx" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
</handlers> 
<validation validateIntegratedModeConfiguration="false" /> 
</system.webServer> 


介意處理程序中的類型和publickeytoken更改!

它必須在「System.ServiceModel」和代替「System.ServiceModel.Activation」「公鑰= 31bf3856ad364e35」作爲微軟這些拆分爲單獨的組件