JSONP和SOAP端点的WCF服务

JSONP和SOAP端点的WCF服务

本文介绍了带有JSON,JSONP和SOAP端点的WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SOAP端点配置了传统的WCF服务.在我的客户项目中,我添加了服务参考"等.这些按预期方式工作.

I configured traditional WCF Services using SOAP end points. In my client project I added the Service Reference, etc. These are working as expected.

我创建了一个启用JSONP的WCF服务,对.svc文件,Web配置等进行了修改.我创建了一个测试客户端页面进行测试.我已成功调用JSONP服务.

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.

但是,我对Web配置所做的更改破坏了SOAP服务的服务参考.我想同时使用两种类型的终点.我不确定如何配置服务和Web配置.

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.

如果仅获取http,则每个操作(无论是用于SOAP还是JSONP)都可以用[WebGet(ResponseFormat = WebMessageFormat.Json)]

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

然后我的服务类别需要:[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

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

将SOAP配置添加到我的webconfig中也会破坏JSONP端点.在客户端调用JSONP不需要客户端服务引用(或代理生成),但是SOAP确实需要吗?

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?

我的服务WebConfig:

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>

推荐答案

该错误清楚地说明了问题所在.您有两个地址相同但绑定不同的端点.不允许.通过绑定webHttpBinding在端点中设置address ="jsonp".您将在/ Service .svc/jsonp

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

这篇关于带有JSON,JSONP和SOAP端点的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 02:36