0
votes

I JSONP enabled my WCF ServiceContract. Client is successfully calling the JSONP Service (OperationContract). I have a number of other OperationContracts (using the same ServiceContract) that I want to expose using basicHttpBinding (SOAP) endpoint - using the same URI. I think my Service WebConfig is set up correctly. When doing such a thing, should I be able to Add the Service Reference (proxy) using the VS "Add Service Reference" dialog window? Or do I need to manually generate client code in codebehind? If I need to manually do it, can anyone provide an example? Or is my Service WebConfig not configured correctly? I am calling the JSONP Service using this: http://Flixsit:1000/FlixsitWebServices.svc/jsonp

Thanks so much...

<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>    

1

1 Answers

0
votes

After tooling around for a while I am creating the ChannelFactory like below (in codebehind). Services are now exposed at both endpoints.

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;
    }