开发者

WCF Services with JSON, JSONP and SOAP End Points

开发者 https://www.devze.com 2023-02-03 23:57 出处:网络
I configured traditional WCF Services using SOAP end points.In my clie开发者_开发百科nt project I added the Service Reference, etc. These are working as expected.

I configured traditional WCF Services using SOAP end points. In my clie开发者_开发百科nt project I added the Service Reference, etc. These are working as expected.

I created a JSONP enabled WCF Service, made the modifications to the .svc file, web config, etc. I created a test client page to test. I am successfully calling the JSONP Service.

However, the changes I made to the web config broke the service reference for the SOAP services. I'd like to use both type of end points. I am not sure how to configure the services and web config.

If http get only, can every operation (regardless if it is intended for SOAP or JSONP) be decorated with: [WebGet(ResponseFormat = WebMessageFormat.Json)]

Then my Service Class needs: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

When I now attempt to Update my Service Reference in my client project I am getting

A binding instance has already been associated to listen URI 'http://flixsit:1000/FlixsitWebServices.svc'. If two endpoints want to share the same ListenUri, they must also share the same binding object instance. The two conflicting endpoints were either specified in AddServiceEndpoint() calls, in a config file, or a combination of AddServiceEndpoint() and config.

Adding SOAP configuration to my webconfig also breaks the JSONP endpoint. Calling JSONP on the client side doesnt require client service reference (or proxy generation), but SOAP does, correct?

My Service WebConfig:

<system.serviceModel>
  <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="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
    </webHttpBinding>
    <basicHttpBinding>
      <binding name="BasicHttpEndpointBinding" />
    </basicHttpBinding>
  </bindings>
  <services>
    <service name="Flixsit.Services.FlixsitWebServices" behaviorConfiguration="DefaultBehaviors">
      <endpoint name="JSONPEndPoint" address=""
                                   binding="webHttpBinding"
                                   bindingConfiguration="webHttpBindingWithJsonP"
                                   contract="Flixsit.Services.IFlixsitWebServices"
                                   behaviorConfiguration="webHttpBehavior" />
      <endpoint name="HttpEndPoint"  address=""
                                   binding="basicHttpBinding"
                                   contract="Flixsit.Services.IFlixsitWebServices" />
      <host>
        <baseAddresses>
          <add baseAddress="http://Flixsit:1000/FlixsitWebServices.svc" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>


The error clearly describes the problem. You have two endpoits with the same address but different bindings. It is not allowed. Set address="jsonp" in the endpoint with binding webHttpBinding. You will call the endpoint on /Service.svc/jsonp

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号