WCF:找不到引用ServiceModel客户端配置部分中的合同“IService”的默认端点元素。在IIS中托管时 [英] WCF: Could not find default endpoint element that references contract 'IService' in the ServiceModel client configuration section. when hosting in IIS

查看:169
本文介绍了WCF:找不到引用ServiceModel客户端配置部分中的合同“IService”的默认端点元素。在IIS中托管时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a WCF service which is being hosted in IIS. I have a WCF client also (a console application). I have used svcutil to build the proxy class and configuration file and then added those to my client project. It built properly. But when I tried to run the program, it is throwing the below exception


无法找到引用合同'IService'的默认端点元素ServiceModel客户端配置部分。这可能是因为没有找到您的应用程序的配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

Could not find default endpoint element that references contract 'IService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

//我的客户端程序代码

//My client program code

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 file of my client is

  <?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中有以下配置

and in the web.config of my service has the below configuration

   <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 )教程试试WCF。

I used this(http://www.wcftutorial.net/WCF-IIS-Hosting.aspx) tutorial to have a try on WCF.

任何人都可以指导我如何解决这个问题吗?

Can anyone guide me how to resolve this ?

推荐答案

快速提问:如果您的客户端应用是名为 myclient.exe ,您的配置是否与EXE在同一目录中并且名为 MyClient.exe.config

Quick question: if your client app is called myclient.exe, is your config in the same directory as the EXE and called MyClient.exe.config ?

你不能从 svcutil output.config $ c> - 您需要将 app.config 添加到您的客户端控制台项目(将重命名为 myclient.exe.config 编译时),或者你需要将 output.config 复制/重命名为 myclient.exe.config 以便您的客户端应用找到并使用它。

You can't just take the output.config from svcutil - you will need to either add a app.config to your client console project (which will be renamed to myclient.exe.config when compiling), or you need to copy/rename the output.config to myclient.exe.config in order for your client app to find and use it.

这篇关于WCF:找不到引用ServiceModel客户端配置部分中的合同“IService”的默认端点元素。在IIS中托管时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆