![](/img/trans.png)
[英]Calling WCF service hosted in Forms Authentication site from a Windows Service
[英]Authentication mode=“Forms” causing redirect in WCF service
我的.NET 4.0 Web應用程序項目中有一個WCF端點。 使用VS2010 WCF測試客戶端,我可以正確連接到服務。 但是,當我去使用該服務時,我收到一般錯誤消息:
內容類型text / html; charset =響應消息的UTF-8與綁定的內容類型不匹配(text / xml; charset = utf-8)。 如果使用自定義編碼器,請確保正確實現IsContentTypeSupported方法。 響應的前1024個字節是:
當我查看IIS Express上的請求時,我得到以下內容:
請求已啟動:POST http:// machinename:port / Services / Services.svc
請求已啟動:GET http:// machinename:port / Services / Services.svc?AspxAutoDectectCookieSupport = 1
請求已結束:“http:// machinename:port / Services / Services.svc”,HTTP狀態為302.0
請求已結束:“http:// machinename:port / Services / Services.svc?AspxAutoDectectCookieSupport = 1”,HTTP狀態為302.0
請求已結束:“http:// machinename:port / Services / Services.svc?AspxAutoDectectCookieSupport = 1”,HTTP狀態為200.0
因此,在POST到服務之后,它似乎被重定向到服務的標准網頁。 然而,當我刪除:
<authentication mode="Forms">
<forms cookieless="AutoDetect" loginUrl="~/Security/LoginClient.aspx" name="FORMAUTH" />
從web.config它的工作原理。 有什么想法發生了什么? 我試圖從身份驗證中刪除該服務所在的文件夾(http://stackoverflow.com/questions/5593720/authentication-mode-forms-causing-errors-in-wcf-end-point),但問題仍然存在。
雖然當我通過IIS Express 7.5運行它時使用Visual Studio開發服務器(Cassini),但無論是否使用身份驗證,都會發生相同的錯誤。
您必須提供在web.config中匿名聯系的Web服務的授權:
<location path="MyWebServices">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
這假設您將所有服務保存在相對於應用程序根目錄的名為MyWebServices
的文件夾中。 您必須允許*
或強制登錄才能訪問。
我在服務地址中使用machinename而不是localhost時遇到同樣的問題。 我確實嘗試使用“baseAddressPrefixFilters”但沒有成功。
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://XLSiteSampleD.aginsurance.intranet/PIXLSiteSample" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
我認為該選項可能是在web.config中使用服務上的相關屬性啟用aspNetCompatibility:[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]但是不是訣竅:(
它只適用於http://localhost/VirtualSite/MyService.svc這樣的地址,沒有域,也沒有baseAddressPrefixFilters!
V.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.