【问题标题】:errors in wcf web.config filewcf web.config 文件中的错误
【发布时间】:2015-10-23 02:28:09
【问题描述】:

我正在开发 wcf 服务,对此我很陌生。这里我根据我看过的视频对web.config文件做了一些修改,但是出现了下面的错误,我不知道它到底在问什么。

谁能帮我解决这个问题?

这是我遇到的错误

错误:无法从 http://localhost:15305/Techieez.svc 获取元数据

如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata 的 MSDN 文档

Exchange 错误 URI:http://localhost:15305/Techieez.svc
元数据包含无法解析的引用:“http://localhost:15305/Techieez.svc”。内容类型应用程序/soap+xml;服务 http://localhost:15305/Techieez.svc 不支持 charset=utf-8。
客户端和服务绑定可能不匹配。

远程服务器返回错误:(415) 无法处理消息,因为内容类型为 'application/soap+xml; charset=utf-8' 不是预期的类型 'text/xml; charset=utf-8'..

HTTP GET 错误 URI:http://localhost:15305/Techieez.svc
HTML 文档不包含 Web 服务发现信息。

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="con" value="uid=sa;password=572572;database=techieez;server=techz"/>
    <add key="from" value="surya.lbits@gmail.com"/>
    <add key="password" value="****"/>
    <add key="webPages:Version" value="2.0" />
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    <add key="webpages:Enabled" value="true" />
    <add key="mail" value="smtp.gmail.com"/>
    <add key="visa" value="surya.lbits@gmail.com"/>
    <add key="port" value="587"/>
    <add key="html" value="true"/>
    <add key="ssl" value="true"/>
    <add key="credit" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />    
    <sessionState cookieless="UseCookies" cookieName="user" timeout="525600" />
    <httpRuntime executionTimeout="500000" targetFramework="4.5" maxRequestLength="2000000" maxQueryStringLength="2000000" enable="true" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_Techieez" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" maxStringContentLength="2097152"
            maxArrayLength="2097152" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="TechieezService.Techieez">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
          contract="TechieezService.ITechieez" />
        <endpoint address="Web" behaviorConfiguration="WebBehaviour"
          binding="webHttpBinding" bindingConfiguration="" name="WebEndPoint"
          contract="TechieezService.ITechieez" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebBehaviour">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="DefaultBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <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="true"/>
  </system.webServer>

</configuration>

【问题讨论】:

  • behaviorConfigurationservice 设置为DefaultBehaviour
  • 为什么你的配置不起作用。 basicHttpBindingwebHttpBinding 不会一起工作。
  • 有什么方法可以将我的配置文件更改为以前的状态。如果可能,请帮助我
  • 不知道之前的状态
  • 重新排列您的系统。服务模型部分正确

标签: c# web-services wcf utf-8


【解决方案1】:

这不一定是错误,它只是意味着您无法访问服务元数据,这通常是出于安全原因进行的。您的服务可能仍然可以正常工作(假设您已经完成了使 WCF 工作所需的其他 10,000 件事情),您只需要知道如何从客户端连接而不依赖于例如“添加服务引用”来自视觉工作室。 但是要启用服务元数据,请将此端点添加到&lt;service&gt;

<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>

【讨论】:

    【解决方案2】:
       <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
          contract="TechieezService.ITechieez" />
    

    您没有为 basicHttpBinding 指定一种行为,如果您转到您列出的 url,它看起来就像会使用的行为。您有一个允许您获取元数据的行为,但您没有使用它。尝试将其更改为:

       <endpoint address="" behaviorConfiguration="DefaultBehaviour" 
       binding="basicHttpBinding" bindingConfiguration="" 
       contract="TechieezService.ITechieez" />
    

    【讨论】:

    • 还是不行,说明有配置错误。
    • 配置错误说明:处理服务该请求所需的配置文件时出错。请查看下面的具体错误详细信息并适当地修改您的配置文件。解析器错误消息:没有名为“DefaultBehavior”的端点行为。
    • 抱歉,我拼错了您的行为名称,我输入的应该是 DefaultBehaviour 而不是 DefaultBehavior。我会更新我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多