调试时通道工厂为null?

时间:2012-03-24 23:27:15

标签: c# wcf visual-studio-2010 rest

当我尝试在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);
    }

1 个答案:

答案 0 :(得分:-1)

WCF需要Web http绑定,其余请看这里我有一个简单的例子,你可以按照它来开始

http://blog.staticvoid.co.nz/2012/02/using-rest-wcf-service.html

我个人更喜欢在代码中执行大部分服务配置,我的示例显示了如何执行此操作。