0

我尝试在 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 端点设置的此属性有关?

4

1 回答 1

1

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

所以我改变了这个

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

            }

对此

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

            }
于 2011-10-14T12:53:40.437 回答