• JS 调用WCF config


    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <connectionStrings>
        <add name="conn" connectionString="server=.;database=Users;uid=sa;pwd=123456;" />
      </connectionStrings>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
     
      <system.serviceModel>
        <behaviors>
          <endpointBehaviors>
            <behavior name="webBehavior">
              <enableWebScript />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="">
              <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
              <serviceMetadata httpGetEnabled="true"/>
              <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
          multipleSiteBindingsEnabled="true" >
          <baseAddressPrefixFilters>
            <add prefix="string"/>
          </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
        <services>
          <service name="IUserTest" >
            <endpoint address="" behaviorConfiguration="webBehavior"
              binding="webHttpBinding" contract="IUserTest" />
            <!--<endpoint address="" binding="basicHttpBinding" contract="ReaderService"  />-->
          </service>
        </services>
        <bindings>
            <webHttpBinding>
              <binding name="webBinding" crossDomainScriptAccessEnabled="true"></binding>
            </webHttpBinding>
        </bindings>
      </system.serviceModel>
     
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
     
    </configuration>

    注:1.在svc的文件中<%@ ServiceHost Language="C#" Debug="true" Service="WCFTest.UserTest" CodeBehind="UserTest.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

    要加上Factory="System.ServiceModel.Activation.WebServiceHostFactory"

    2.在代码上加上 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    3.在接口上加上 [WebInvoke(ResponseFormat = WebMessageFormat.Json,UriTemplate="/方法名", Method="GET" ,BodyStyle = WebMessageBodyStyle.Wrapped)]

  • 相关阅读:
    Hystrix解析(三)
    Hystrix解析(二)
    在阿里云开发平台编写第一个 HelloWorld 程序
    Jenkins与Docker的自动化CI/CD实战
    网页计数器例子
    ServletContext 对象
    Session
    Cookie
    Request 对象作用域
    转发,重定向(包括请求中文乱码解决)
  • 原文地址:https://www.cnblogs.com/ZJ199012/p/2395746.html
Copyright © 2020-2023  润新知