WCF:在 ServiceModel 客户端配置部分中找不到引用协定“IService”的默认端点元素。当托管在 IIS 中时

2024-05-12

我有一个 WCF 服务托管在 IIS 中。我还有一个 WCF 客户端(控制台应用程序)。我用过svcutil构建代理类和配置文件,然后将它们添加到我的客户端项目中。它建造得很好。但是当我尝试运行该程序时,它抛出以下异常

在 ServiceModel 客户端配置部分中找不到引用协定“IService”的默认端点元素。这可能是因为找不到应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。

//我的客户端程序代码

namespace MyFirstWCFClient
{
 class Program
 {
    static void Main(string[] args)
    {
        ServiceClient objClient = new ServiceClient();
        Console.WriteLine("Client calling the service....");

        string strName=Console.ReadLine();
        Console.WriteLine(objClient.HelloWorld("Shyju"));
        Console.Read();

    }
 }
}

我的客户端的Output.config文件是

  <?xml version="1.0" encoding="utf-8"?>
   <configuration>
    <system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost/IISHostedserviceTest/Service.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
            contract="IService" name="WSHttpBinding_IService">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
     </client>
 </system.serviceModel>
</configuration>

在我的服务的 web.config 中有以下配置

   <system.serviceModel>
   <services>
    <service name="Service" behaviorConfiguration="ServiceBehavior">
    <!-- Service Endpoints -->
    <endpoint address="http://localhost/IISHostedserviceTest/Service.svc" binding="wsHttpBinding" contract="IService">
      <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="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>
 </system.serviceModel>

我用过这个(http://www.wcftutorial.net/WCF-IIS-Hosting.aspx http://www.wcftutorial.net/WCF-IIS-Hosting.aspx)尝试使用 WCF 的教程。

谁能指导我如何解决这个问题?


快速问题:如果您的客户端应用程序被调用myclient.exe,您的配置与 EXE 位于同一目录中并称为MyClient.exe.config ?

你不能只采取output.config from svcutil- 您需要添加一个app.config到您的客户端控制台项目(将重命名为myclient.exe.config编译时),或者您需要复制/重命名output.config to myclient.exe.config以便您的客户端应用程序找到并使用它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

WCF:在 ServiceModel 客户端配置部分中找不到引用协定“IService”的默认端点元素。当托管在 IIS 中时 的相关文章

随机推荐