2017-06-16 7 views
0

javascript関数でWebサービスを使用できるようにするためのチュートリアルや設定方法はありません。私のPC上で、ChromeはちょうどWebサービス用にIISを設定する

500(内部サーバーエラー)

をスローし、サーバからWebページを実行し、IEはクロスオリジンリソース共有(必要

をスローしますCORS)。

CORSのプリフライトが必要。

必要なクロスドメイン設定をwebconfigに追加しましたが、まだ動作しません。

<configuration> 
    <system.web> 
     <customErrors mode="Off"/> 
     <compilation strict="false" explicit="true" targetFramework="4.5" /> 
     <httpRuntime targetFramework="4.5" /> 
     <webServices> 
     <!-- added because asmx --> 
     <protocols> 
      <add name="HttpGet"/> 
      <add name="HttpPost"/> 
     </protocols> 
     </webServices> 
    </system.web> 
    <system.webServer> 
    <httpProtocol> 
     <customHeaders> 
     <add name="Access-Control-Allow-Origin" value="*" /> 
     <add name="Access-Control-Allow-Headers" value="Content-Type" /> 
     <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" /> 
     </customHeaders> 
    </httpProtocol> 
    </system.webServer> 

</configuration> 

Javascriptを:

function GetMember() { 
    $.ajax({ 
     type: "POST", 
     url: "https://www.mywebsite.org/Callsickapp/Webservice1.asmx/HelloWorld", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: OnGetMemberSuccess, 
     error: OnGetMemberError 
    }); 
} 
document.getElementById("btnCallService").onclick = GetMember; 
function OnGetMemberSuccess(data, status) { 
    //jQuery code will go here... 

    document.getElementById("answers").innerHTML= data.d; 
} 
function OnGetMemberError(request, status, error) { 
    //jQuery code will go here... 
    document.getElementById("answers").innerHTML= request.statusText 
} 

私は何をしないのですか?

答えて

0

Visual Studioで生成されたWebサービス.vbファイルの先頭にあるコメントを実際に読む必要がありました。

'To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 

' <System.Web.Script.Services.ScriptService()> _ 

シンプルな「HelloWorld」Webサービスやチュートリアルの他のWebサービスは現在正常に動作しています。

関連する問題