添加行为配置会导致 (415) Unsupported Media Type.HTTP GET Error

发布于 2024-12-10 16:41:56 字数 3041 浏览 0 评论 0原文

当我添加行为配置时,我从 wcftester 得到以下信息 远程服务器返回错误: (415) Unsupported Media Type.HTTP GET Error

服务 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) 请访问您可以访问的通信基础服务 检查您是否已在指定的位置启用元数据发布 地址

远程服务器返回错误:(415) 不支持的媒体类型.HTTP 获取错误 URI:http://localhost:2622/MyRemoteHostService.svc HTML 文档不包含 Web 服务发现信息。

When I add in behaviorConfiguration I get the following from wcftester
The remote server returned an error: (415) Unsupported Media Type.HTTP GET Error

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>

Error:

Cannot obtain Metadata from
http://localhost:2622/MyRemoteHostService.svc If this is a Windows (R)
Communication Foundation service to which you have access, please
check that you have enabled metadata publishing at the specified
address

The remote server returned an error: (415) Unsupported Media Type.HTTP
GET Error URI: http://localhost:2622/MyRemoteHostService.svc The
HTML document does not contain Web service discovery information.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯℡ 2024-12-17 16:41:56

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

I got a 415 error message took me more than a day to find the cause, turns out that our web.config on the server is different to dev, it specifies a different binding which means the binding is different between the client (SL) and the wcf service on the server which seems to cause a 415 message (kinda makes sense). Your bindings above look correct, could be worth re-checking. Have you tried updating the service reference after adding the behaviorConfiguration, sometimes it works. Unfortunately HTTP error codes can be very misleading at times...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文