2012-03-24 49 views
0

当我尝试在WCF测试客户端模式下使用WCF休息调用的GetData合同我得到这个消息:通道工厂null调试?

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); 
    } 
+0

当我改变wsHttpBinding到webHttpBinding重做主机后,我收到了错误。那为什么不能接受webHttpBinding呢? – 2012-03-24 23:38:04

回答

-1

WCF需要Web http绑定,其余的看看这里我有一个简单的例子,你可以按照上手

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

我个人比较喜欢在代码中做很多的服务配置,我的例子显示了如何做到这一点。

+0

链接是死的芽!有什么别的机会吗? – 2012-03-25 13:11:16

+0

现在回来了。有DNS问题 – 2012-03-26 06:14:30

+0

你怎么样然后路由绑定在您的Global.ascx服务如何打开Global.ascx文件? – 2012-03-27 19:49:02