Web Services WCF测试服务无法添加服务

e0bqpujr  于 2023-01-26  发布在  其他
关注(0)|答案(1)|浏览(177)

我正在使用Visual Studio进行一个学校项目,我将创建一个简单的WCF服务应用程序Web服务,我需要使用WCF测试客户端进行测试。
我开发了这个服务,但是当我运行调试器时,它打开了一个Web浏览器,我复制了指向IService1.svc文件的链接,并尝试将其添加到测试客户端,但它失败了,并抱怨无法获得 meta数据。
我在一个新项目的新解决方案中尝试了这个方法,同样的事情。
我的Web.config文件:

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

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.8.1" />
    <httpRuntime targetFramework="4.8.1"/>
  </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="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>

我是否遗漏了测试Web服务的任何步骤?

nszi6y05

nszi6y051#

根据wcf配置文件的不同,您可以看到没有终结点和服务协定的部分。您可能错过了以下<service.model>部分:

<services> 
<service name="Namespace.Service1"> 
<endpoint address="" binding="basicHttpBinding" contract="Namespace.IService1" /> 
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
</service> 
</services>

相关问题