Shy*_*yju 4 iis wcf wcf-client
我有一个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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的客户端的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>
Run Code Online (Sandbox Code Playgroud)
并在我的服务的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>
Run Code Online (Sandbox Code Playgroud)
我用这个(http://www.wcftutorial.net/WCF-IIS-Hosting.aspx)教程试试WCF.
任何人都可以指导我如何解决这个问题?
mar*_*c_s 23
快速提问:如果您的客户端应用程序被调用myclient.exe
,您的配置是否与EXE在同一目录中并被调用MyClient.exe.config
?
您不能只是从中output.config
获取svcutil
- 您需要添加一个app.config
到您的客户端控制台项目(myclient.exe.config
在编译时将重命名为),或者您需要复制/重命名output.config
为myclient.exe.config
以便客户端应用程序查找和使用它.
您必须使用指定端点配置名称的客户端的构造函数,例如.
objClient = new ServiceClient ("WSHttpBinding_IService");
Run Code Online (Sandbox Code Playgroud)
这将告诉代理使用您在配置文件中指定的配置.
归档时间: |
|
查看次数: |
44055 次 |
最近记录: |