【问题标题】:WCF 4 and multiple endpoint bindingsWCF 4 和多端点绑定
【发布时间】:2012-04-01 03:20:18
【问题描述】:

我渴望将相同的合同和服务公开为 basicHttpBinding 和 webHttpBinding 以便能够进行 POST 调用。不知何故,当我查看 wsdl 时,它永远不会看到 webHttpBinding 的端点。我做错了什么?

<system.serviceModel>
<services>
  <service name="MyService">
    <endpoint address =""
              binding="basicHttpBinding"
              name="EndpointBasic"
              contract="IMyService"/>

    <endpoint address ="PostMethod"
              binding="webHttpBinding"
              name="EndpointJson"
              contract="IMyService"/>
    <host>
      <baseAddresses>
        <add baseAddress ="http://localhost/WebsiteName/MyService.svc"/>
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="basicBinding" />
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="Postbinding"
             maxBufferSize="65536"
             maxReceivedMessageSize="2000000000"
             transferMode="Streamed">
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="JsonBehavior">
      <webHttp defaultOutgoingResponseFormat="Json" />
    </behavior>
  </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

谢谢!

【问题讨论】:

  • 我还要提一下,我想从一个 html 页面调用一个 POST 来进行这个 webhttpbinding ......如果这有什么不同的话。

标签: wcf wcf-binding wcf-4


【解决方案1】:

我有以下适用于 SOAP 和 REST 的服务元素条目:

<service name="XMLService.RestAndSoapService" behaviorConfiguration="default">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="RestBinding" name="SampleService" contract="XMLService.IRestAndSoapService" />
        <endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="noSecurity" contract="XMLService.IRestAndSoapService" />
      </service>

配置中的注意事项:

  1. 在您的服务元素中,您的合同和服务名称不是完全限定的。确保他们完全合格,即。包括命名空间和接口。

  2. 您尚未将 bindingConfiguration 指定为 webHttpEndpoint 的“Postbinding”和 basicHttpBinding 端点的“basicBinding”

因此,通过上述更改,您的配置可能如下所示:

<service name="namespace.MyService">
        <endpoint address =""
                  bindingConfiguration="basicBinding"
                  binding="basicHttpBinding"
                  name="EndpointBasic"
                  contract="namespace.IMyService"/>

        <endpoint address ="PostMethod"
                  bindingConfiguration="Postbinding"
                  binding="webHttpBinding"
                  name="EndpointJson"
                  contract="namespace.IMyService"/>
        <host>
          <baseAddresses>
            <add baseAddress ="http://localhost/WebsiteName/MyService.svc"/>
          </baseAddresses>
        </host>
      </service>

【讨论】:

  • 另外,如果您希望应用“JsonBehavior”,请将behaviorConfiguration="JsonBehavior" 属性添加到“PostMethod”端点元素。
  • 好吧,这似乎有所不同......但是当我转到 localhost/WebsiteName/MyService.svc/PostMethod 时,我得到一个页面,上面写着 Endpoint not found。
  • nm... 我想我忘记了 PostMethod 是地址。我需要添加除此之外的操作。呵呵
猜你喜欢
  • 2011-07-06
  • 2011-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
相关资源
最近更新 更多