私は、コードの角度側はこの `XML形式での角度でWCFサービスを消費
mainApp.factory('MediaService', ['$http', function ($http) {
var factory = {};
factory.getMediaLoops = function() {
return $http.post("http://localhost:62467/MediaLoopService.MediaLoop.svc/GetMediaLoops");
}
return factory;}]);
のように見えるこの`
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Xml)]
public string GetMediaLoops()
{
string strFileName = "GetMediaLoops_response.xml";
string strResult = GetFileData(strFileName);
return strResult;
}`
のように見える機能GetMediaLoopsを持つMediaServiceLoop.svcファイルを持っています
Controller code:
MediaService.getMediaLoops()
.then(function (response) {
$scope.media = response.data;
}, function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
`
私はPostmanとChrome Network()の両方で回答を得ることができましたが、「No」Access-Control-Allow-Originヘッダが要求されたリソースに存在します。 Origin 'http://localhost:2206'はアクセスが許可されていないため、コードフローはgetMediaLoops角度呼び出しの応答とエラーブロックをスキップします。
また、上記のエラーのために以下のコードをGlobal.asaxファイルに追加しました上記のエラーを取得し、すべてのヘルプは
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST, PUT, DELETE");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}
ありがとう、魅力的なように働いた:) –