1

基本的 WCF 服务项目,包括 protobuf-net .dll 库。

打开网络浏览器并转到 localhost/wcf/service1.svc,一切正常。

现在转到 localhost/wcf/service1.svc/help,在浏览器控制台上显示 400 Bad Request(如 firebug)。

这是web.config

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding1" messageEncoding="Mtom">
      <security mode="None"></security>
    </binding>
  </basicHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior name="Service1Behavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>

  <endpointBehaviors>
    <behavior name="protoEndpointBehavior">
      <protobuf />
    </behavior>
  </endpointBehaviors>
</behaviors>

<extensions>
  <behaviorExtensions>
    <add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net"/>
  </behaviorExtensions>
</extensions>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />

<services>
  <service name="WcfService1.Service1" behaviorConfiguration="Service1Behavior">
    <endpoint address="" contract="WcfService1.IService1" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding1" behaviorConfiguration="protoEndpointBehavior" />
  </service>
</services>

4

1 回答 1

1

只需要这个来查看帮助页面:

<bindings>
  <webHttpBinding>
    <binding name="WebHttpBinding1" >
      <security mode="None"></security>
    </binding>
  </webHttpBinding>
<bindings>

<behaviors>
  <endpointBehaviors>
    <behavior name="protoEndpointBehavior">
      <webHttp helpEnabled="true"/>
      <protobuf />
    </behavior>
  </endpointBehaviors>
</behaviors>

<services>
  <service name="WcfService1.Service1" behaviorConfiguration="Service1Behavior">
    <endpoint address="" contract="WcfService1.IService1" binding="webHttpBinding" bindingConfiguration="WebHttpBinding1" behaviorConfiguration="protoEndpointBehavior" />
  </service>
</services>

同样如 Mark 所说,basicHttpBinding 允许消息编码 Mtom,从而提高效率。但是 webHttpBinding 不允许。

于 2012-06-01T11:21:49.770 回答