2012年1月21日 星期六

The test form is only available for requests from the local machine.

最近在測試ASP.NET的WebService功能,遇到了“The test form is only available for requests from the local machine.”訊息(中文版訊息為:測試表單只適用於來自本機電腦的要求。),在查詢過MSDN文件後明白要在web.config做相關設定,預設web.config檔的<webServices>項目在子項目<protocols>只啟用HttpSoap 和 Documentation,只需加上HttpPost即可,以下為程式碼範例

      <webServices>
         <protocols>
            <add name="HttpPost"/>
         </protocols>
      </webServices>

另外在<protocols>項目還有一個HttpGet,HttpPost與HttpGet的不同在HttpPost是網頁必須透過post的方式呼叫WebService,HttpGet則只需知道WebService所提供的方法網址即可,如以下所示
http://192.168.1.3/webservice.asmx/HelloWorld

針對公開WebService後的安全性問題可參考Building Secure Web Services

沒有留言:

張貼留言