我已经用SIML和Database对机器人进行了训练。在静态IP上部署时遇到问题。当我尝试将机器人部署到本地主机以外的URL上时,例如http://192.168.0.25:8086/bot,它在控制台中显示访问被拒绝。此外,部署在本地主机上,并使用Inetmgr部署在IIS服务器上。然后使用相同域中的计算机的IP地址和端口访问它,则会显示主机名无效。我正在使用AJAX获取响应,它在我的本地主机上工作得很好。但在本地主机以外的计算机上访问时表示,由于CORS策略,请求已被阻止。你能给我一些关于如何成功部署机器人的见解吗?
发布于 2020-01-16 19:08:46
如果您正在使用WCF Self - Hosted,那么您将不得不使服务在跨域上工作。
您的应用程序可以利用http://enable-cors.org/server_wcf.html中的一些CORS
下面是我使用的配置的副本:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime
maxRequestLength="2147483647"
executionTimeout="300" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
<add name="Access-Control-Max-Age" value="1728000" />
</customHeaders>
</httpProtocol>
</system.webServer>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="crossOriginResourceSharingBehavior" type="Work.Server.EnableCrossOriginResourceSharingBehavior, Work.Server, Version=1.0.0.0, Culture=neutral" />
</behaviorExtensions>
</extensions>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="Work.Server.WorkService">
<endpoint address="" behaviorConfiguration="restfulBehaviour" binding="webHttpBinding" contract="Work.Server.IWorkService" bindingConfiguration="webHttpBindingWithJsonP" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehaviour">
<webHttp automaticFormatSelectionEnabled="false" />
<crossOriginResourceSharingBehavior />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
</configuration>https://stackoverflow.com/questions/59767608
复制相似问题