WCF Services with JSON, JSONP and SOAP End Points

不想你离开。 提交于 2020-01-03 02:29:07

问题


I configured traditional WCF Services using SOAP end points. In my client 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>

回答1:


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



来源:https://stackoverflow.com/questions/4688545/wcf-services-with-json-jsonp-and-soap-end-points

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!