无法在Visual Studio

时间:2015-05-07 14:08:25

标签: wcf visual-studio-2013 binding bad-request mismatch

我有一个问题,这真的很烦人......

我使用3种简单方法创建了一个WCF服务。该服务在开发服务器和生产服务器上运行良好。

2周后,我被要求添加更多功能,所以我打开了解决方案,并尝试在进行任何更改之前构建/调试服务,以检查其状态。

不幸的是,在尝试了我在网上找到的7-8种不同的解决方案后,仍无法调试它,而且我一直都会遇到同样的错误。

  

错误:无法从http://localhost:50930/StService.svc获取元数据   如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。   有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455上的MSDN文档。

     

WS-Metadata Exchange错误URI:http://localhost:50930/StService.svc   元数据包含无法解析的引用:' http://localhost:50930/StService.svc'。   内容类型application / soap + xml;服务http://localhost:50930/StService.svc不支持charset = utf-8。

     

客户端和服务绑定可能不匹配。   远程服务器返回错误:(415)无法处理消息,因为内容类型' application / soap + xml;字符集= UTF-8'不是预期的类型&text; / xml;字符集= UTF-8' ..

     

HTTP GET错误URI:http://localhost:50930/StService.svc下载' http://localhost:50930/StService.svc'时出错。请求失败,HTTP状态为400:错误请求。

我尝试编辑web.config(尽管dev和& live servsers都是相同的,除了数据库连接),在每个Temp文件夹,项目文件夹,禁用和删除任何防火墙或防病毒等方面赋予权限。不能让它发挥作用......

有什么想法吗?

根据请求,这是web.config:

<?xml version="1.0"?>
<configuration>
  <system.web>
      <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
    <caching>
      <sqlCacheDependency enabled="true">
        <databases>
          <add connectionStringName="PhotosSqlServer" name="PhotosSqlServer" pollTime="1000"/>
        </databases>
      </sqlCacheDependency>
    </caching>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name ="wsMessage">
          <security mode ="Message">
            <message clientCredentialType ="Windows"/>
          </security>
        </binding>
      </wsHttpBinding>
      <netTcpBinding>
        <binding name="NetTcpBinding_IStService" maxReceivedMessageSize="5242880" maxConnections="10">
          <readerQuotas maxDepth="64" maxStringContentLength="5242880" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          <security mode="None"></security>
        </binding>
      </netTcpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="false"/>
  </system.webServer>
</configuration>

1 个答案:

答案 0 :(得分:0)

<system.serviceModel>标记内添加:

    <service name="YourAppNameSpace.StService">
    <endpoint address="" binding="wsMessage" bindingConfiguration="NetTcpBinding_IStService"
      contract="YourAppNameSpace.IStService" />
    <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:50930/StService" />
      </baseAddresses>
    </host>
  </service>

我不确定参数。但您肯定在App.config上缺少service-endpoint信息。