0

我创建了一个用作 WCF 客户端的控制台应用程序。app.config 包含以下内容:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="WebHttpBinding_IWebContentService">
                    <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                        messageVersion="Soap12" writeEncoding="utf-8">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    </textMessageEncoding>
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:1252/SomeService.svc" binding="customBinding" bindingConfiguration="WebHttpBinding_IWebContentService"
                contract="WebContentClient.IWebContentService" name="WebHttpBinding_IWebContentService" />

        </client>


    </system.serviceModel>
</configuration>

当我运行它时,我收到以下错误:

The address property on ChannelFactory.Endpoint was null 

端点元素有一个地址属性,但我不确定我应该分配什么属性。我在本地主机上运行我的网络服务。

更新 1:

我添加了地址并更新了原始代码。但是我收到错误消息,说没有端点监听地址=“http://localhost:1252/SomeService.svc”。如果我访问 wcf url,我可以看到 Web 服务。

4

2 回答 2

2

您的自定义绑定配置不正确。您应该指定一个传输元素,如 httptransport。

下面是一个有效配置的例子:

<customBinding>
    <binding name="myCustomHttpBinding">
        <textMessageEncoding />
        <httpTransport / >
    </binding >    
</customBinding >

为什么要使用自定义绑定?根据服务的不同,有许多更易于使用的绑定(basicHttpBinding、webHttpBinding...)。

注意:由于异常,我认为您的客户端代码也不正确。

于 2012-09-27T19:06:52.810 回答
0

您需要将其分配给 Web 服务的地址。如果它是 localhost 上的 WCF Web 服务,它可能是以下形式:

http://localhost[:port]/<path>/SomeService.svc
于 2012-09-27T18:54:44.510 回答