调试时通道工厂为空
本文关键字:工厂 通道 调试 | 更新日期: 2023-09-27 18:28:50
当我尝试在wcf测试客户端模式下使用wcf-rest调用GetData合约时,我得到以下消息:
The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified.
at System.ServiceModel.ChannelFactory.CreateEndpointAddress(ServiceEndpoint endpoint)
at System.ServiceModel.ChannelFactory`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannelInternal()
at System.ServiceModel.ClientBase`1.get_Channel()
at Service1Client.GetData(String value)
这是主机的配置文件:
<system.serviceModel>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="http://localhost:26535/Service1.svc" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webHttp" >
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService1.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
代码:
[ServiceContract(Namespace = "")]
public interface IService1
{
//[WebInvoke(Method = "POST", UriTemplate = "Data?value={value}")]
[OperationContract]
[WebGet(UriTemplate = "/{value}")]
string GetData(string value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
public class Service1 : IService1
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
WCF和rest需要Web http绑定。看看这里,我有一个简单的例子,你可以按照它来开始
http://blog.staticvoid.co.nz/2012/02/using-rest-wcf-service.html
我个人更喜欢在代码中进行大部分服务配置,我的示例展示了如何做到这一点。