【问题标题】:Configuring WCF JSONP and SOAP Endpoints Listening at the same URI配置 WCF JSONP 和 SOAP 端点侦听同一 URI
【发布时间】:2011-06-09 11:39:06
【问题描述】:

我 JSONP 启用了我的 WCF ServiceContract。客户端成功调用 JSONP 服务 (OperationContract)。我有许多其他 OperationContracts(使用相同的 ServiceContract),我想使用 basicHttpBinding (SOAP) 端点公开 - 使用相同的 URI。我认为我的 Service WebConfig 设置正确。做这样的事情时,我应该能够使用 VS“添加服务引用”对话框窗口添加服务引用(代理)吗?还是我需要在代码隐藏中手动生成客户端代码?如果我需要手动完成,谁能提供一个例子?还是我的 Service WebConfig 配置不正确?我正在使用这个调用 JSONP 服务:http://Flixsit:1000/FlixsitWebServices.svc/jsonp

非常感谢...

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<behaviors>
  <endpointBehaviors>
    <behavior name="webHttpBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="DefaultBehaviors">          
      <serviceMetadata httpGetEnabled="true" />          
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <webHttpBinding>
    <binding name="JSONPBinding" crossDomainScriptAccessEnabled="true" />
  </webHttpBinding>
  <basicHttpBinding>
    <binding name="SOAPBinding" />
  </basicHttpBinding>
</bindings>
<services>
  <service name="Flixsit.Services.FlixsitWebServices" behaviorConfiguration="DefaultBehaviors">
    <clear />
    <endpoint name="JSONPEndPoint" address="jsonp"
                                   binding="webHttpBinding"
                                   bindingConfiguration="JSONPBinding"
                                   contract="Flixsit.Services.IFlixsitWebServices"
                                   behaviorConfiguration="webHttpBehavior" />
    <endpoint name="HttpEndPoint"  address=""
                                   binding="basicHttpBinding"
                                   bindingConfiguration="SOAPBinding"
                                   contract="Flixsit.Services.IFlixsitWebServices" />
    <host>
      <baseAddresses>
        <add baseAddress="http://Flixsit:1000/FlixsitWebServices.svc" />
      </baseAddresses>
    </host>
  </service>
</services>    

【问题讨论】:

    标签: wcf jsonp


    【解决方案1】:

    在使用了一段时间后,我正在创建如下所示的 ChannelFactory(在代码隐藏中)。服务现在在两个端点都公开。

    try
        {
            EndpointAddress address = new EndpointAddress("http://Flixsit:1000/FlixsitWebServices.svc");
            WSHttpBinding binding = new WSHttpBinding();
            ChannelFactory<IFlixsitWebServices> factory = new ChannelFactory<IFlixsitWebServices>(binding, address);
            IFlixsitWebServices channel = factory.CreateChannel();
    
            //call the service operation  
            var customer = channel.GetCustomers();
    
            GridView1.DataSource = customer;
            GridView1.DataBind();
    
            //close the channel
            ((ICommunicationObject)channel).Close();
    
            //close factory
            factory.Close();
        }
        catch (Exception ex)
        {
            //log ex;
        }
    

    【讨论】:

      猜你喜欢
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-29
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      相关资源
      最近更新 更多