首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >调试时通道工厂为空?

调试时通道工厂为空?
EN

Stack Overflow用户
提问于 2012-03-25 07:27:15
回答 1查看 1.2K关注 0票数 0

当我尝试在wcf test client模式下使用wcf rest调用GetData协定时,我得到了这样的消息:

代码语言:javascript
运行
复制
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)

这是主机的配置文件:

代码语言:javascript
运行
复制
  <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>

代码:

代码语言:javascript
运行
复制
[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);
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-25 07:51:45

Web http绑定是WCF和rest所必需的。请看这里,我有一个简单的示例可供您参考

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

就我个人而言,我更喜欢在代码中完成大部分服务配置,我的示例展示了如何做到这一点。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9856595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档