【问题标题】:WCF consume by dotnet winfom client and config entrydotnet winfom 客户端和配置条目使用 WCF
【发布时间】:2013-02-07 14:48:03
【问题描述】:

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

我有几个关于 wcf 客户端配置条目的问题

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

1) 如果我删除下面的这些条目会发生什么......我不能从客户端调用服务吗?

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

3) 当我要进行服务调用时,如何从 cient 端明确提及 Web 服务 url?

<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>

【问题讨论】:

    标签: wcf


    【解决方案1】:

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

    1) 你需要在某个地方提供它。如果你把它们从配置中拿走。你应该用代码来做。

    2) WCF 具有 ABC 的基本规则。地址,绑定和合同。同样,如果它已经在您的配置文件中,您不必说什么。

    对于多个客户。您还可以从配置文件中提及端点名称。举例

    MyClient someClientObject = new MyClient("WSDualHttpBinding_ICommService");
    

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

    您可以通过简单的方式做到这一点。无参数。

    MySVCClient svcproxy = new MySVCClient ();

    您的服务合同需要有条目。 您还可以使用如下构造函数...使用端点地址和投标等。

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

    因为您在这里定义了代码中的所有内容。您不需要配置文件中的任何内容。

    【讨论】:

    • 如果我按照您所说的方式实例化代理类,例如 MyClient someClientObject = new MyClient("WSDualHttpBinding_ICommService");行得通吗? MyClient ctor 参数不带参数,那么我如何传递端点名称。
    • 在 config 中定义端点时。你的名字。如果您仔细查看配置文件。我在上面的示例中使用了端点名称。否则,您必须实例化我在上一个示例中提到的不需要任何配置的方式。
    猜你喜欢
    • 2021-04-17
    • 2011-05-03
    • 2013-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    相关资源
    最近更新 更多