添加behaviorConfiguration cause(415)不支持的媒体类型.HTTP GET错误

时间:2011-10-18 13:04:54

标签: silverlight wcf

当我添加behaviorConfiguration时,我从wcftester获得以下内容 远程服务器返回错误:(415)不支持的媒体类型.HTTP GET错误

service web.config

  <system.serviceModel>
    <services>
      <service  behaviorConfiguration="MaxConfig" name="MyRemoteHostService">
        <endpoint address="" binding="basicHttpBinding"
                  bindingConfiguration="BasicHttpBinding_MyRemoteHostService"
                  contract="My.Framework.Web.MyRemoteHostService" />

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false"
      multipleSiteBindingsEnabled="true" />



    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_MyRemoteHostService"
            maxBufferPoolSize="2147483647"
            maxReceivedMessageSize="2147483647"
            maxBufferSize="2147483647">
          <readerQuotas
              maxArrayLength="2147483647"
              maxBytesPerRead="2147483647"
              maxDepth="2147483647"
              maxNameTableCharCount="2147483647"
              maxStringContentLength="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>



    <behaviors>
      <serviceBehaviors>
        <behavior name="MaxConfig">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>


  </system.serviceModel>

ServiceReferences.ClientConfig

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_MyRemoteHostService" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      <endpoint address="http://localhost:2622/MyRemoteHostService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyRemoteHostService"
        contract="MyServiceReference.MyRemoteHostService" name="BasicHttpBinding_MyRemoteHostService" />
    </client>
  </system.serviceModel>

错误:

  

无法从中获取元数据   http://localhost:2622/MyRemoteHostService.svc如果这是Windows(R)   请访问您的Communication Foundation服务   检查您是否已在指定的位置启用元数据发布   地址

     

远程服务器返回错误:(415)Unsupported Media Type.HTTP   GET错误URI:http://localhost:2622/MyRemoteHostService.svc   HTML文档不包含Web服务发现信息。

1 个答案:

答案 0 :(得分:1)

我收到了一条415错误消息,花了我一天多才找到原因,结果发现我们服务器上的web.config与dev不同,它指定了不同的绑定,这意味着客户端之间的绑定不同( SL)和服务器上的wcf服务似乎导致415消息(有点意义)。您上面的绑定看起来是正确的,值得重新检查。您是否尝试在添加behaviorConfiguration后更新服务引用,有时它可以正常工作。不幸的是,HTTP错误代码有时会产生误导......