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);
                        }
                    }
                });
  • 相关阅读:
    jar包制作
    eclipse 编译出错(java.io.ObjectInputStream)的解决办法
    Onmouseover被调用多次
    【驱动】——模块参数
    【驱动】——驱动入门用例
    【linux】——FTP出现500 OOPS: cannot change directory的解决方法
    【驱动】——错误: 初始值设定项里有未知的字段‘ioctl’
    【C】——动态库中函数的作用范围
    【C】——如何生成静态库和动态库
    【C】——C语言字符串比较函数
  • 原文地址:https://www.cnblogs.com/server126/p/2873488.html
Copyright © 2011-2022 走看看