WCF 错误:ChannelFactory.Endpoint 上的地址属性为空 [英] WCF Error: The address property on ChannelFactory.Endpoint was null
问题描述
我创建了一个用作 WCF 客户端的控制台应用程序.app.config 包含以下内容:
I created a console application which is serving as a WCF client. The app.config consists of the following:
<?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>
当我运行它时,我收到以下错误:
When I run it I get the following error:
The address property on ChannelFactory.Endpoint was null
端点元素有一个地址属性,但我不确定我应该为该属性分配什么.我在本地主机上运行我的网络服务.
The endpoint element has an address property but I am not sure what I am suppose to assign that property. I am running my web service on localhost.
更新 1:
我添加了地址并更新了原始代码.但是我收到错误消息,说没有端点侦听地址 =http://localhost:1252/SomeService.svc".如果我访问 wcf 网址,我可以看到网络服务.
I added the address and I have updated the original code. But I get the error back saying that There was no endpoint listening to the address="http://localhost:1252/SomeService.svc". If I visit the wcf url I can see the web service.
推荐答案
您的自定义绑定的配置不正确.您应该指定一个传输元素,如 httptransport.
The configuration of your custombinding is incorrect. You should specify a transport element like httptransport.
以下是有效配置的示例:
Here is an example of a valid configuration :
<customBinding>
<binding name="myCustomHttpBinding">
<textMessageEncoding />
<httpTransport / >
</binding >
</customBinding >
你为什么使用自定义绑定?根据服务,有许多更易于使用的绑定(basicHttpBinding、webHttpBinding 等).
Why are you using a custom binding ? depending on the service, there are many bindings (basicHttpBinding, webHttpBinding, ...) easier to use.
注意:由于异常,我认为您的客户端代码也不正确.
Note : I think your client code is incorrect too because of the exception.
这篇关于WCF 错误:ChannelFactory.Endpoint 上的地址属性为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!