WCF由dotnet winfom客户端和配置条目消耗

时间:2013-02-07 14:48:04

标签: wcf

我是WCF的新手,但我对Web服务(ASMX文件)

有点熟悉

我对wcf客户端配置条目

有几个问题

当我们创建任何Web服务(ASMX)代理时,没有任何内容添加配置文件,如下面的条目,但在WCF的情况下,下面的条目添加。我只需要知道以下条目的重要性。

1)如果我删除以下条目,那么将会发生什么......我不能从客户端调用该服务吗?

2)告诉我当我们从客户端调用Web服务时,如果在客户端添加了多个端点地址,我怎么说我的服务将使用哪个端点地址来调用服务?

3)当我打电话时,如何从客户端明确提及网络服务网址?

<system.serviceModel>
    <bindings>
        <wsDualHttpBinding>
            <binding name="WSDualHttpBinding_ICommService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:00:05"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00" />
                <security mode="Message">
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsDualHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost/CommService/"
            binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_ICommService"
            contract="Services.ICommService" name="WSDualHttpBinding_ICommService">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

1 个答案:

答案 0 :(得分:1)

是的,这些是WCF所需的重要配置。您可以通过配置文件或代码提供它。

1)你需要提供一些地方。如果你带他们来配置。你应该在代码中这样做。

2)WCF有ABC的基本规则。地址,约束和合同。如果它已经存在于您的配置文件中,您也不必再说什么了。

适用于多个客户。您还可以在配置文件中提及端点名称。 ForExample

MyClient someClientObject = new MyClient("WSDualHttpBinding_ICommService");

3)默认情况下,当您添加服务引用操作时,WCF运行时会为您提供客户端代理。

你可以这样简单地做到这一点。参

MySVCClient svcproxy = new MySVCClient();

您需要输入服务合同。 您还可以使用构造函数...使用端点Adddress和Bidning等。

BasicHttpBinding myBinding= new BasicHttpBinding(SecurityMode.None);   
EndpointAddress endpointAdd= new EndpointAddress("http://localhost/CommService/");
MySVCClient svcproxy = new MySVCClient (myBinding, endpointAdd);

由于您在此处定义代码中的所有内容。配置文件中不需要任何内容​​。