[英]How to handle cross domain request between an asp.net web page and a WCF service hosted in IIS?
我編寫了WCF Web服務,該服務通過IIS-7托管在Windows Server 2012中。 服務器的公共IP當前處於打開狀態(防火牆已禁用)。 我可以使用瀏覽器很好地獲取元數據和wsdl文檔,並且可以通過該IP向Visual Studio添加服務引用。 但是,當我的asp.net網頁調用WCF服務方法時,它給我405-不允許使用方法錯誤。
我認為問題出在跨域發布。 我可能是錯的,但這是有道理的,因為從應用程序訪問wcf服務時,我只會收到錯誤。
我將如何避免這個問題?
這是我的界面:
[ServiceContract]
public interface IDataPortalWCFService
{
[OperationContract]
string HelloWorldTest(string u, string p);
[OperationContract]
string HelloWorldTest2(string u, string p, string str);
[OperationContract]
string HelloWorldTest3(string u, string p);
[OperationContract]
DataTable GetBAQResults(string u, string p, string BAQName, DataTable BAQParameters);
[OperationContract]
string GetBAQResultsAsJSON(string u, string p, string BAQName, string BAQParameters);
}
在IIS中托管WCF服務時,處理跨域標頭應與在IIS中托管的任何其他類型的網站基本相同。 以下問題應可幫助您找到解決方案...
解決此問題的另一種方法是簡單地重用域。
例如供您的網站使用:-
www.mygreat.com
和供您使用的api
api.mygreat.com
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.