zoukankan      html  css  js  c++  java
  • Wcf resut服务

    外部地址调用Wcf resut服务,POST方式好像不支持呀,我是实验了多次也没有成功。

    这里演示一下GET方式。 客户端调用使用的JsonP

    //接口
    namespace Jiang.WebServ
    {
        [ServiceContract(Name = "IServices", Namespace = "http://www.msdn.com/Serv/Medicine")]
        public interface IServices
        {
            [OperationContract(Name = "GetName")]
            [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            string GetName (string str);
      }
    }
    //实现
    namespace Jiang.WebServ
    {
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
        public class Services : IServices
        {
            #region IServices 成员
           public string GetName(string str)
             { return "Hello :"+str;}
        }
    }
    <?xml version="1.0"?>
    <configuration>
      <connectionStrings>
        <add name="OracleConnectionString" connectionString="Password=*****;User ID=*****;Data Source=ORACLE41"/>
      </connectionStrings>
      <system.serviceModel>
    <!--添加这个-->
        <standardEndpoints>
          <webScriptEndpoint>
            <standardEndpoint name="" crossDomainScriptAccessEnabled="true"/>
          </webScriptEndpoint>
        </standardEndpoints>
    <!--    -->
        <services>
          <service name="Jiang.WebServ.Services" behaviorConfiguration="WebbehaviorConfig">
            <endpoint address="" binding="webHttpBinding" contract="Jiang.WebServ.IServices" bindingConfiguration="httpBindingConfig"/>
          </service>
        </services>
        <serviceHostingEnvironment>
          <serviceActivations>
    <!-- 设置虚拟.svc文件-->
            <add service="Jiang.WebServ.Services" relativeAddress="WebServ.svc"/>
          </serviceActivations>
        </serviceHostingEnvironment>
        <bindings>
          <webHttpBinding>
            <binding name="httpBindingConfig" crossDomainScriptAccessEnabled="true" openTimeout="00:05:00" receiveTimeout="00:05:00" sendTimeout="00:05:00" maxBufferPoolSize="10240000" maxBufferSize="10240000" maxReceivedMessageSize="10240000">
              <security mode="None"/>
            </binding>
          </webHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="WebbehaviorConfig">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior>
              <webHttp helpEnabled="true"/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <directoryBrowse enabled="true"/>
      </system.webServer>
      <system.web>
        <compilation debug="true"/>
      </system.web>
    </configuration>

    客户端

    $.ajax({
                    type: "GET",
                    dataType: "jsonp",
                    jsonp: "callback",
                    jsonpCallback: "callback",
                    url: "http://192.168.1.14/webSvc.svc/GetName?str=jiang",
                    success: function (data) {
                        if (data.length == 0) {
                            $(control).remove();
                        } else {
                            alert(data);
                        }
                    }
                });
  • 相关阅读:
    在MVC中更新ModelFirst Entity Framework POCO实体外键的方法
    美国行照片集十四:洛杉矶拉斯维加斯之旅
    深入ASP.NET MVC之三:Controller的激活
    美国行照片集之十三:感恩节之旅
    深入ASP.NET MVC 之一:IIS到路由表
    博客样式改版
    关于如何用string保存二进制数据的问题
    XSI IPC机制的优缺点
    C,C++,java,python对比
    grunt requireJS 的基础配置
  • 原文地址:https://www.cnblogs.com/server126/p/2873488.html
Copyright © 2011-2022 走看看