0

enter code here我的 wcf 服务没有在测试客户端中运行,而是通过浏览器运行,并且当我通过 jquery 获取时

可能有什么问题

错误:无法添加服务。服务元数据可能无法访问。确保您的服务正在运行并公开元数据。

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="SimpleServiceBehavior">
      <serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <webHttpBinding>
    <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
  </webHttpBinding>
</bindings>
<services>
  <service name="WcfService6.Service1">
    <endpoint address="" binding="webHttpBinding"
              bindingConfiguration="webHttpBindingWithJsonP" contract="WcfService6.IService1"
              behaviorConfiguration="webHttpBehavior"/>
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
</services>

4

2 回答 2

0

您可能使用配置为使用 HTTP 方法的 REST Web 服务。WCF 测试客户端是一个 SOAP 客户端,需要访问 Web 服务元数据才能工作。

将元数据配置条目添加到您的 Web 服务配置:http: //msdn.microsoft.com/en-us/library/ms788760.aspx

在您发布的配置中,您配置了两个 Web 服务。您应该在当前 web 服务上启用元数据,而不是配置另一个 web 服务:

<system.serviceModel>
<behaviors>
  <endpointBehaviors>
    <behavior name="webHttpBehavior" >
      <serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
<bindings>
  <webHttpBinding>
    <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
  </webHttpBinding>
</bindings>
<services>
  <service name="WcfService6.Service1">
    <endpoint address="" binding="webHttpBinding"
              bindingConfiguration="webHttpBindingWithJsonP" contract="WcfService6.IService1"
              behaviorConfiguration="webHttpBehavior"/>
      <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
</services>

请阅读:WCF REST 服务在 WCFTestClient 中不可见

于 2013-07-08T09:52:44.347 回答
0

您必须使用配置文件为服务启用元数据交换,这将在 ServiceBehavior 下

<behaviors>
  <serviceBehaviors>
    <behavior name="SimpleServiceBehavior">
      <serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
    </behavior>
  </serviceBehaviors>
</behaviors> 

试试下面的链接

http://msdn.microsoft.com/en-us/library/ms734765.aspx

于 2013-07-08T10:04:27.210 回答