1

一段时间以来,我一直在研究启用 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 值不匹配。IIS 的值为 WhenSupported,而 WCF 传输的值为 Never.. ---> System.NotSupportedException:在 IIS 上配置的扩展保护设置与在传输上配置的设置不匹配。ExtendedProtectionPolicy.PolicyEnforcement 值不匹配。

这是我脚本中的代码:

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

我究竟做错了什么?

4

1 回答 1

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
于 2013-10-29T03:09:21.117 回答