名称为“AutomatedFormatSelectionContentTypePropertyName”的属性不存在

时间:2011-10-06 07:49:53

标签: wcf wcftestclient

我在WcfTestClient

中尝试调用我的服务时遇到此错误

我的配置:

 <services>
      <service behaviorConfiguration="MetadataBehavior" name="ServiceModel.Service">
        <endpoint address="soap" binding="basicHttpBinding" name="Soap"
          contract="ServiceModel.IService"  />
        <endpoint address="rest" behaviorConfiguration="jsonBehavior"
          binding="webHttpBinding" bindingConfiguration="webHttpBindingSettings"
          name="Json" contract="ServiceModel.IService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://dev.add.com/Service.svc/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MetadataBehavior">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="jsonBehavior">
          <webHttp automaticFormatSelectionEnabled="true" helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

为什么我收到此错误,它与json endpoint的此属性集相关联?

1 个答案:

答案 0 :(得分:0)

我的错误。我正在检查REST响应消息是否包含AutomatedFormatSelectionContentTypePropertyName属性,但在SOAP调用中它不包含它并触发错误。

所以我改变了这个

if (OperationContext.Current.OutgoingMessageProperties.ContainsKey("AutomatedFormatSelectionContentTypePropertyName"))
            {

            }

到这个

if (OperationContext.Current.OutgoingMessageProperties != null && OperationContext.Current.OutgoingMessageProperties.ContainsKey("AutomatedFormatSelectionContentTypePropertyName"))
            {

            }