Ajax启用WCF服务无法正常工作

时间:2013-10-29 00:13:52

标签: asp.net ajax wcf iis

我一直在研究支持Ajax的WCF服务,但从未使用过Windows身份验证。它直接从VS 2010运行时工作正常,但当部署到Web服务器时,它会抛出错误。

这是我的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无法处理请求。发件人信息:   System.ServiceModel.Activation.HostedHttpRequestAsyncResult / 51925686   异常:System.ServiceModel.ServiceActivationException:服务   由于异常,无法激活'/Services/GISService.svc'   在编译期间。异常消息是:扩展保护   在IIS上配置的设置与在上配置的设置不匹配   运输。 ExtendedProtectionPolicy.PolicyEnforcement值   不匹配。在WCF传输时,IIS的值为WhenSupported   值为Never .. ---&gt; System.NotSupportedException:扩展名   IIS上配置的保护设置与设置不匹配   在传输上配置。该   ExtendedProtectionPolicy.PolicyEnforcement值不匹配。 IIS   当WCF Transport的值为。时,其值为WhenSupported   从不。

这是我脚本中的代码:

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

我做错了什么?

1 个答案:

答案 0 :(得分:0)

也许你需要一个Ajax绑定。以下示例支持Json / Xml /和Plain 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