WCF元数据包含无法解析的引用 [英] WCF Metadata contains a reference that cannot be resolved

查看:824
本文介绍了WCF元数据包含无法解析的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了几个小时寻找这个错误,我已经测试了几乎所有它在谷歌。

I've spent a couple of hours searching about this error, and I have tested almost everything it's on Google.

我想用TCP,.NET4和VS2010,在C#中访问服务。

我有一个非常小的服务:

I Have a very tiny service:

namespace WcfService_using_callbacks_via_tcp
{
    [ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
    public interface IService1
    {
        [OperationContract]
        string Test(int value);
    }

    public interface ICallback
    {
        [OperationContract(IsOneWay = true)]
        void ServerToClient(string sms);
    }
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class Service1 : IService1
    {
        public string Test(int value)
        {
            ICallback the_callback = OperationContext.Current.GetCallbackChannel<ICallback>();
            the_callback.ServerToClient("Callback from server, waiting 1s to return value.");
            Thread.Sleep(1000);
            return string.Format("You entered: {0}", value);
        }

    }
}


有了这个Web.config文件:


With this Web.config:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfService_using_callbacks_via_tcp.Service1" behaviorConfiguration="Behaviour_Service1">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:5050/Service1" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="DuplexNetTcpBinding_IService1" contract="WcfService_using_callbacks_via_tcp.IService1"/>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="mexTcp" contract="IMetadataExchange"/>
      </service>
    </services>

    <bindings>
      <!--
        TCP Binding
      -->
      <netTcpBinding>
        <binding name="DuplexNetTcpBinding_IService1" sendTimeout="00:00:01"
                 portSharingEnabled="true">

        </binding>

        <binding name="mexTcp" portSharingEnabled="true">
          <security mode="None" />
        </binding>
      </netTcpBinding>


    </bindings>

    <behaviors>
      <serviceBehaviors>
        <!--
          Behaviour to avoid a rush of clients and to expose metadata over tcp
        -->
        <behavior name="Behaviour_Service1">
          <serviceThrottling maxConcurrentSessions="10000"/>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>

        <behavior>
          <!-- 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>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>


这code主办的:


And this code to host it:

static void Main(string[] args)
{
    Uri base_address = new Uri("net.tcp://localhost:5050/Service1");
    ServiceHost host = null;
    try
    {
        // Create the server
        host = new ServiceHost(typeof(Service1), base_address);
        // Start the server
        host.Open();
        // Notify it
        Console.WriteLine("The service is ready at {0}", base_address);
        // Allow close the server
        Console.WriteLine("Press <Enter> to stop the service.");
        Console.ReadLine();
        // Close it
        host.Close();
    }
    catch (Exception ex)
    {
        // Opus an error occurred
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine(string.Format("Host error:\r\n{0}:\r\n{1}", ex.GetType(), ex.Message));
        Console.ReadLine();
    }finally
    {
        // Correct memory clean
        if(host != null)
            ((IDisposable)host).Dispose();
    }
}


现在我要创建的客户端,但我是不是更多钞票。我用直接添加服务引用和SvcUtil工具,但我收到此错误:


Now I want to create the client, but I it is not posible. I've used Add Service Reference and svcutil directly, but I am receiving this error:

C:\\ Program Files文件(x86)的\\微软的Visual Studio 10.0 \\ VC> svcutil.exe的
  的net.tcp:// LOC alhost:5050 /服务1微软(R)服务模式
  元数据工具[微软(R)的Windows(R)通信基础,
  版本4.0.30319.1]版权所有(c)Microsoft公司。所有权利
  保留。

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>svcutil.exe net.tcp://loc alhost:5050/Service1 Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1] Copyright (c) Microsoft Corporation. All rights reserved.

试图从元数据下载
  '的net.tcp://本地主机:5050 /服务1利用了W S-元数据交换。这个
  URL不支持DISCO。微软(R)服务模型元数据工具
  [微软(R)的Windows(R)通信基础版本
  4.0.30319.1]版权所有(c)Microsoft公司。保留所有权利。

Attempting to download metadata from 'net.tcp://localhost:5050/Service1' using W S-Metadata Exchange. This URL does not support DISCO. Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1] Copyright (c) Microsoft Corporation. All rights reserved.

错误:无法从获得的net.tcp元数据://本地主机:5050 /服务1

Error: Cannot obtain Metadata from net.tcp://localhost:5050/Service1

如果这是Windows(R)通信基础服务,您
  有ACCE SS,请检查您是否已经启用元数据发布
  在指定的地址的ESS。如需帮助实现元数据发布,
  请参阅MSDN documentat离子在
   http://go.microsoft.com/fwlink/?LinkId=65455

If this is a Windows (R) Communication Foundation service to which you have acce ss, please check that you have enabled metadata publishing at the specified addr ess. For help enabling metadata publishing, please refer to the MSDN documentat ion at http://go.microsoft.com/fwlink/?LinkId=65455.

WS-元数据交换错误
  URI:的net.tcp://本地主机:5050 /服务1

WS-Metadata Exchange Error URI: net.tcp://localhost:5050/Service1

元数据包含无法解析的引用:的net.tcp://本地主机:5050 / Service1的。

Metadata contains a reference that cannot be resolved: 'net.tcp://localhost: 5050/Service1'.

套接字连接被中止。这可能是一个错误加工塑料纳克你的消息或接收超时被超出所致
  远程主机,或者未derlying网络资源的问题。本地
  套接字超时是00:04:59.9863281

The socket connection was aborted. This could be caused by an error processi ng your message or a receive timeout being exceeded by the remote host, or an un derlying network resource issue. Local socket timeout was '00:04:59.9863281'.

硒公顷forzado拉interrupción日乌纳conexiónexistente POR EL主机偏远落后地区

Se ha forzado la interrupción de una conexión existente por el host remoto

如果您想了解更多的帮助,请键入SvcUtil工具/?

If you would like more help, type "svcutil /?"

所以,我可以承载没有问题的服务,但我不能创建代理。


So, I can host the service without problems but I can not create the proxies.

我试过差不多,我发现任何配置,但我认为目前的web.config是正确的。有行为,安全性,和绑定使用MEX,由端点使用。

I've tried almost any config I've found, but I think the current web.config is correct. There are the behaviours, the security, and the bindings using mex, used by the endpoints.

我试图创建一个app.config并将其设置为与svcutil.exe的同一文件夹中。

I've tried to create an app.config and set it to the same folder with svcutil.exe.

推荐答案

您缺少服务配置

<system.serviceModel>
  <services>
    <service name="WcfService_using_callbacks_via_tcp.Service1" 
      behaviorConfiguration="Behavior_Service1">
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:5050/Service1" />
        </baseAddresses>
      </host>
      <endpoint address="" contract="WcfService_using_callbacks_via_tcp.IService1"
         binding="netTcpBinding" bindingConfiguration="DuplexNetTcpBinding_IService1" />
      <endpoint address="mex" contract="IMetadataExchange" binding="mexTcpBindng" />
    </service>
  </services>
  ...
</system.serviceModel>

使用这个配置你不应该需要code中定义的基址。

With this config you should not need to define base address in code.

这篇关于WCF元数据包含无法解析的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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