EDIT:
我修改后web.config
我没有收到错误,这很好......然后我添加一个新页面(html)并编写这个小代码来使用服务,如下所示:
$("#btn12").click(function (event) {
$.getJSON('http://localhost:3576/MyService.svc/GetCurrentUser', {},
function (data) {
alert(data);
});
//return false;
});
我在 FireBug 中看到以下错误:
http://localhost:3576/MyService.svc/GetCurrentUser
400 Bad Request
注意:我已经在同一个 wcf 项目上添加了 html 页面并自行运行该项目,所以我假设该服务也在运行......
这里可能出了什么问题?
END EDIT
我刚刚创建了一个新的 wcf 服务,当我从 VS 中按 f5 时,我在 WCF 测试客户端窗口中收到此错误:
添加服务失败。服务元数据可能无法访问。确保您的服务正在运行并公开元数据。
错误:无法从中获取元数据http://localhost:3696/MobileService.svc http://localhost:3696/MobileService.svc如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布。如需启用元数据发布的帮助,请参阅 MSDN 文档:http://go.microsoft.com/fwlink/?LinkId=65455 http://go.microsoft.com/fwlink/?LinkId=65455.
WS-元数据交换错误
URI: http://localhost:3696/MyService.svc http://localhost:3696/MyService.svc
元数据包含无法解析的引用:'http://localhost:3696/MyService.svc http://localhost:3696/MyService.svc'.
没有端点在监听http://localhost:3696/MyService.svc http://localhost:3696/MyService.svc可以接受该消息。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。
无法连接到远程服务器
无法连接,因为目标机器主动拒绝 127.0.0.1:3696
HTTP 获取错误
URI: http://localhost:3696/MyService.svc http://localhost:3696/MyService.svc
下载时出错'http://localhost:3696/MyService.svc http://localhost:3696/MyService.svc'.
无法连接到远程服务器
无法连接,因为目标机器主动拒绝 127.0.0.1:3696
我的配置:
<behaviors>
<endpointBehaviors>
<behavior name="MyService.MyService">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:2812/MyService.svc" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyService.MyService"
behaviorConfiguration="metadataBehavior">
<endpoint
address="http://localhost/MyService.svc"
binding="customBinding"
bindingConfiguration="jsonpBinding"
behaviorConfiguration="MyService.MyService"
contract="MyService.IMyService"/>
</service>
</services>
<bindings>
<customBinding>
<binding name="jsonpBinding">
<jsonpMessageEncoding/>
<httpTransport manualAddressing="true"/>
</binding>
</customBinding>
</bindings>
<extensions>
<bindingElementExtensions>
<add name="jsonpMessageEncoding" type="Microsoft.Ajax.Samples.JsonpBindingExtension, MyService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bindingElementExtensions>
</extensions>