2013-10-29 33 views
1

我一直在使用支持Ajax的WCF服务,但从未使用Windows身份验证。从VS 2010直接运行时它工作正常,但是当部署到Web服务器时,它会引发错误。启用了Ajax的WCF服务不起作用

这是我的web.config:

<configuration> 
    <system.web> 
    <compilation debug="false" targetFramework="4.0"/> 
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> 
    <authentication mode="Windows" /> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpEndpointBinding"> 
      <security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Windows" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="GISAlloc.Services.GISServiceBehavior"> 
      <serviceMetadata httpGetEnabled="false"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="GISAlloc.Services.GISServiceAspNetAjaxBehavior"> 
      <enableWebScript/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 
    <services> 
     <service name="GISAlloc.Services.GISService" behaviorConfiguration="GISAlloc.Services.GISServiceBehavior"> 
     <endpoint address="" bindingConfiguration="BasicHttpEndpointBinding" binding="basicHttpBinding" contract="GISAlloc.Services.GISService"/> 
     </service> 
    </services> 
    </system.serviceModel> 
</configuration> 

但是当我尝试获取数据,从asp.net,我得到错误500,这是从我的Windows日志:

WebHost failed to process a request. Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/51925686 Exception: System.ServiceModel.ServiceActivationException: The service '/Services/GISService.svc' cannot be activated due to an exception during compilation. The exception message is: The extended protection settings configured on IIS do not match the settings configured on the transport. The ExtendedProtectionPolicy.PolicyEnforcement values do not match. IIS has a value of WhenSupported while the WCF Transport has a value of Never.. ---> System.NotSupportedException: The extended protection settings configured on IIS do not match the settings configured on the transport. The ExtendedProtectionPolicy.PolicyEnforcement values do not match. IIS has a value of WhenSupported while the WCF Transport has a value of Never.

这是我的脚本代码:

var navService = new GISAlloc.GISService(); 
navService.GetGISList(shownav, null, null); 

我在做什么错了?

+0

我已在IIS一些更新,现在我可以查看该服务,但从JavaScript调用时,我现在得到另一个错误:无法加载资源:服务器响应状态为400(错误请求) – user2930100

+0

您可以发布您的服务代码和JavaScript调用? – Saranya

+0

我做了更多的操作,并将svc转换为asmx,所有OperationContracts被更改为webmethods,并启用了[System.Web.Script.Services.ScriptService],并且它工作正常。我不得不将JavaScript更改为GISAlloc.Services.GISService.GetGISList(shownav,null,null); – user2930100

回答

0

也许你需要一个Ajax绑定。下面的例子支持的Json/XML /和纯XML

<system.serviceModel> 
    <bindings> 
     <webHttpBinding> 
     <binding name="WebxmlHttp"> 
      <security mode="None"/> 
     </binding> 
     <binding name="WebjsonHttp"> 
      <security mode="None"/> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="SecureServiceBehavior" name="xxxx.Web.Services.Reporting.ServiceImplementation.Ixxxx"> 
     <clear/> 
     <endpoint address="xml" binding="webHttpBinding" bindingConfiguration="WebxmlHttp" behaviorConfiguration="xmlBehavior" name="webXMLHttpBinding" contract="xxxx.Web.Services.Reporting.ServiceContracts.Ixxxx"/> 
     <endpoint address="json" binding="webHttpBinding" bindingConfiguration="WebjsonHttp" behaviorConfiguration="jsonBehavior" name="webJSONHttpBinding" contract="xxxx.Web.Services.Reporting.ServiceContracts.Ixxxx"/> 
     </service> 
    </services> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="jsonBehavior"> 
      <webHttp defaultOutgoingResponseFormat="Json"/> 
     </behavior> 
     <behavior name="xmlBehavior"> 
      <webHttp defaultOutgoingResponseFormat="Xml"/> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="SecureServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
      <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647"/> 
      <serviceTimeouts transactionTimeout="00:03:00"/> 
      <serviceThrottling maxConcurrentCalls="10" maxConcurrentSessions="10" maxConcurrentInstances="10"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <!--Need aspNet compatibility here to get at the HttpRequest. This is a true shortcut to getting the requests original URL prior to being 
    passed of to the wcf protocols. The "original" http reuest uri is used in the HMACMD5 Authentication 
    This ensures that the ASP.NET pipeline is fired up and configured for every incoming request 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    --> 
    </system.serviceModel> 

套用这个配置的功能可以使用这些选项被称为:

https://MyService.svc/<json|xml|pox>/SomeEntity/SomeID 
相关问题