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 

エンドポイント要素にはアドレス プロパティがありますが、そのプロパティを何に割り当てればよいかわかりません。localhost で Web サービスを実行しています。

更新 1:

アドレスを追加し、元のコードを更新しました。しかし、address="http://localhost:1252/SomeService.svc" をリッスンしているエンドポイントがなかったというエラーが返されます。wcf url にアクセスすると、Web サービスが表示されます。

4

2 に答える 2

2

custombinding の構成が正しくありません。httptransport のようなトランスポート要素を指定する必要があります。

有効な構成の例を次に示します。

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

なぜカスタム バインディングを使用しているのですか? サービスによっては、より使いやすい多くのバインディング (basicHttpBinding、webHttpBinding、...) があります。

注:例外のため、クライアントコードも正しくないと思います。

于 2012-09-27T19:06:52.810 に答える
0

Web サービスのアドレスに割り当てる必要があります。ローカルホスト上の WCF Web サービスの場合、おそらく次の形式になります。

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