Windows Server 2008中的RESTFUL服务托管 [英] RESTFUL service hosing in windows server 2008

查看:86
本文介绍了Windows Server 2008中的RESTFUL服务托管的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在Windows Server 2008 R2中部署了 服务

我试图使用该服务更新数据库中的记录.我已使用"put"方法进行更新.

我通过ajax调用了服务,如下所示-

Hi,

I deployed the service in windows server 2008 R2

i tried to update a record in db using the service. i have used ''put'' method for update.

i called the service by ajax as follows -

<script type="text/javascript">

        function test() {
        ;

            var AssetUpdate = {
              
                logInInfo: { UserName: 'mark.ritter@e-isg.com', Password: 'password' },
                asset: {
                    AssetName: 'a',
                    Barcode: '1',
                    AssetDescription: '1',
                    AssetIDInternal: 'D2907B1D-8AE9-49D8-A905-65DD356858B2',
                    PeopleIDInternal: 'ED98D0E6-4AB4-41D4-9EC2-5A289D33595B',
                    LocationIDInternal: '48A986EA-00BE-46FC-A377-C19B63DA540C',
                    AssetCategoryIDInternal: '6E41C53F-BA24-4A8B-9892-79AF133549C7',
                    SiteIDInternal: '8A63BD8B-6B1A-4C91-96E5-3DE44FF07BC0',
                    AssetUsageID: '1',
                    AssetConditionID: '1',
                    AssetStatus: '12',
                    AssetSerialNo: '123',
                    Price: '12',
                    PurchaseDate: '01/01/2012',
                    PurchaseOrderNo: '55',
                    Quantity: '456',
                    Vendor: '67',
                    IsActive: 'True',
                    AuditDate: '01/01/2012',
                    AuditStatus: '4353',
                    Asset_UID: '1',
                    DataGatherID: '34',
                    ActualCost: '345',
                    FederalCost: '435',
                    MatchCost: '324',
                    Mfg: 'TEST',
                    Model: '1',
                    POLine: '1',
                    POStatus: '1',
                    ScannerDeviceCode: '1',
                    DateModified: '01/01/2012'
                }, AssetIDInternal: '5afb3768-db2f-42d1-8c47-3da008c6cdee'
            };

            try {
                $.ajax({
                     url: "http://172.16.0.110:80/vamsyncservices/api/Asset/UpdateAsset",
                  
                    type: "PUT",
                    dataType: 'json',

                   data: AssetUpdate,

                    success: function () {
                        alert("Done");
                        alert('Asset Updated successfully.');
                    },
                    Failure: function () {
                        alert("Fails");
                    }


                });
            }
            catch (e) {
                alert(e);
            }
        }     

    </script>


****************************************************** ****************************
配置文件:


******************************************************************************
Config file :

<system.webServer>
   <modules>
      <remove name="WebDAVModule"/>
   </modules>

   <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>
   <handlers>
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
   </handlers>
 </system.webServer>



****************************************************** ************************************

当我运行脚本时,出现如下错误



**********************************************************************************

When i run the script i got an error as follows

"XMLHttpRequest cannot load http://rest.e-isg.com/vamsyncservices/api/Asset/UpdateAsset. Origin http://localhost:52265 is not allowed by Access-Control-Allow-Origin."



帮助?



Help ?

推荐答案

.ajax({ url:" , 类型:" , dataType:' json', 数据:AssetUpdate, 成功:功能(){ alert(" ); alert(' 资产已成功更新.'); }, 失败:功能(){ alert(" ); } }); } 捕获(e){ 警报(e); } } </script>
.ajax({ url: "http://172.16.0.110:80/vamsyncservices/api/Asset/UpdateAsset", type: "PUT", dataType: 'json', data: AssetUpdate, success: function () { alert("Done"); alert('Asset Updated successfully.'); }, Failure: function () { alert("Fails"); } }); } catch (e) { alert(e); } } </script>


****************************************************** ****************************
配置文件:


******************************************************************************
Config file :

<system.webServer>
   <modules>
      <remove name="WebDAVModule"/>
   </modules>

   <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>
   <handlers>
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
   </handlers>
 </system.webServer>



****************************************************** ************************************

当我运行脚本时,出现如下错误



**********************************************************************************

When i run the script i got an error as follows

"XMLHttpRequest cannot load http://rest.e-isg.com/vamsyncservices/api/Asset/UpdateAsset. Origin http://localhost:52265 is not allowed by Access-Control-Allow-Origin."



帮助吗?



Help ?


这篇关于Windows Server 2008中的RESTFUL服务托管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆