添加服务失败.服务元数据可能无法访问.确保您的服务正在运行并公开元数据.` [英] Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.`

查看:22
本文介绍了添加服务失败.服务元数据可能无法访问.确保您的服务正在运行并公开元数据.`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我修改了 web.config 之后,我没有得到很好的错误......然后我添加了一个新页面(html)并编写了这个小代码来使用这样的服务:

After I modified the web.config and I don't get error that's good.... then I add a new page (html) and write this small code to consume the service like this:

 $("#btn12").click(function (event) {
                $.getJSON('http://localhost:3576/MyService.svc/GetCurrentUser', {},
                function (data) {
                    alert(data);
                });
                //return false;
            });

我在 FireBug 中看到以下错误:

I see the following error in my FireBug:

http://localhost:3576/MyService.svc/GetCurrentUser
400 Bad Request

注意:我在同一个 wcf 项目中添加了 html 页面并自行运行该项目,所以我假设该服务也在运行......

Note: I have added html page on the same wcf project and running the project it self so I am assuming the service is also running ...

这里可能有什么问题?

结束编辑

我刚刚创建了一个新的 wcf 服务,当我从 VS 中按 f5 时,我在 WCF 测试客户端窗口中收到此错误:

I have just created a new wcf services and when I hit f5 from VS and I get this error in WCF Test Client window :

添加服务失败.服务元数据可能无法访问.确保您的服务正在运行并公开元数据.

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.

错误:无法从 http://localhost:3696/MobileService.svc 获取元数据如果是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布.有关启用元数据发布的帮助,请参阅位于 http://go.microsoft.com 的 MSDN 文档/fwlink/?LinkId=65455.

Error: Cannot obtain Metadata from http://localhost:3696/MobileService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.

WS-元数据交换错误
URI:http://localhost:3696/MyService.svc
元数据包含无法解析的引用:http://localhost:3696/MyService.svc".

WS-Metadata Exchange Error
URI: http://localhost:3696/MyService.svc
Metadata contains a reference that cannot be resolved: 'http://localhost:3696/MyService.svc'.

http://localhost:3696/MyService.svc 上没有端点可以接受消息.这通常是由不正确的地址或 SOAP 操作引起的.有关更多详细信息,请参阅 InnerException(如果存在).

There was no endpoint listening at http://localhost:3696/MyService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

无法连接到远程服务器
无法建立连接,因为目标机器主动拒绝它 127.0.0.1:3696
HTTP GET 错误
URI:http://localhost:3696/MyService.svc
下载http://localhost:3696/MyService.svc"时出错.
无法连接到远程服务器
无法建立连接,因为目标机器主动拒绝它 127.0.0.1:3696

Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:3696
HTTP GET Error
URI: http://localhost:3696/MyService.svc
There was an error downloading 'http://localhost:3696/MyService.svc'.
Unable to connect to the remote server
No connection could be made because the target machine actively refused it 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>

推荐答案

您需要向您的服务添加元数据交换 (mex) 端点:

You need to add a metadata exchange (mex) endpoint to your service:

<services>
   <service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
      <endpoint 
          address="http://localhost/MyService.svc" 
          binding="customBinding" bindingConfiguration="jsonpBinding" 
          behaviorConfiguration="MyService.MyService"
          contract="MyService.IMyService"/>
      <endpoint 
          address="mex" 
          binding="mexHttpBinding" 
          contract="IMetadataExchange"/>
   </service>
</services>

现在,您应该能够获取服务的元数据

Now, you should be able to get metadata for your service

更新: 好的,所以您只是从 Visual Studio 启动它 - 在这种情况下,它将托管在内置 Web 服务器 Cassini 中.但是,那个野兽支持 HTTP - 您没有在绑定中使用该协议...

Update: ok, so you're just launching this from Visual Studio - in that case, it will be hosted in Cassini, the built-in web server. That beast however only supports HTTP - you're not using that protocol in your binding...

此外,由于您在 Cassini 中托管此服务,您的服务地址将由 Cassini 指定 - 您无需定义任何内容.

Also, since you're hosting this in Cassini, the address of your service will be dictated by Cassini - you don't get to define anything.

所以我的建议是:

  • 尝试使用http绑定(刚刚用于测试)
  • 让它工作
  • 知道它可以工作后,将其更改为自定义绑定并将其托管在 IIS 中

所以我将配置更改为:

<behaviors>
   <serviceBehaviors>
      <behavior name="metadataBehavior">
         <serviceMetadata httpGetEnabled="true" />
      </behavior>
   </serviceBehaviors>
</behaviors>
<services>
   <service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
      <endpoint 
          address=""   <!-- don't put anything here - Cassini will determine address -->
          binding="basicHttpBinding" 
          contract="MyService.IMyService"/>
      <endpoint 
          address="mex" 
          binding="mexHttpBinding" 
          contract="IMetadataExchange"/>
   </service>
</services>

完成后,尝试在 Visual Studio 解决方案中对 SVC 文件执行在浏览器中查看 - 如果这不起作用,您仍然存在某种主要问题.

Once you have that, try to do a View in Browser on your SVC file in your Visual Studio solution - if that doesn't work, you still have a major problem of some sort.

如果有效 - 现在您可以在 VS 中按 F5,您的服务应该会出现,并使用 WCF 测试客户端应用,您应该能够从 a) Cassini 启动您的服务的地址或 b) mex 地址(Cassini 的地址 + /mex)获取您的服务元数据)

If it works - now you can press F5 in VS and your service should come up, and using the WCF Test Client app, you should be able to get your service metadata from a) the address that Cassini started your service on, or b) the mex address (Cassini's address + /mex)

这篇关于添加服务失败.服务元数据可能无法访问.确保您的服务正在运行并公开元数据.`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆