简体   繁体   English

无法在WCF应用程序中添加服务引用

[英]unable to add service reference in wcf application

the problem : when adding service reference -> chosing the address http://localhost:8000 -> pressing GO 问题:添加服务引用时->选择地址http:// localhost:8000- >按GO

There was an error downloading 'http://localhost:8000'. 下载“ http:// localhost:8000”时出错。
Unable to connect to the remote server 无法连接到远程服务器
No connection could be made because the target machine actively refused it 127.0.0.1:8000 无法建立连接,因为目标计算机主动拒绝了127.0.0.1:8000
Metadata contains a reference that cannot be resolved: 'http://localhost:8000/'. 元数据包含无法解析的引用:“ http:// localhost:8000 /”。
There was no endpoint listening at http://localhost:8000/ that could accept the message. http:// localhost:8000 /上没有侦听终结点的端点可以接受该消息。
This is often caused by an incorrect address or SOAP action. 这通常是由不正确的地址或SOAP操作引起的。
See InnerException, if present, for more details. 有关更多详细信息,请参见InnerException(如果存在)。
Unable to connect to the remote server 无法连接到远程服务器
No connection could be made because the target machine actively refused it 127.0.0.1:8000 无法建立连接,因为目标计算机主动拒绝了127.0.0.1:8000
If the service is defined in the current solution, try building the solution and adding the service reference again. 如果服务是在当前解决方案中定义的,请尝试构建解决方案并再次添加服务引用。

The service contract : 服务合同:

[ServiceContract(Namespace="http://www.thatindigogirl/2011/12")]
public interface IHelloIndigo
{
    [OperationContract]
    void DoWork();
}    

The service : 服务 :

public class HelloIndigo : IHelloIndigo
{
    public void DoWork()
    {
        throw new NotImplementedException();
    }
}

The host's app.config : 主机的app.config

 <system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="serviceBehavior">
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="serviceBehavior" name="HelloIndigo">
          <host>
            <baseAddresses>
              <add baseAddress="http://localhost:8000" />
            </baseAddresses>
          </host>
          <endpoint address="HelloIndigoService" binding="basicHttpBinding"
                 name="basicHttp" contract="Host.IHelloIndigo" />
            <endpoint binding="mexHttpBinding"  name="mex"
                contract="IMetadataExchange" />                
        </service>
    </services>
</system.serviceModel>
  • This solution was rebuilt from an vs2008 to vs2010 I changed the framework to 4.0 in both projects client and host . 该解决方案从vs2008重建为vs2010,我在项目客户端和宿主中都将框架更改为4.0。
  • The configurations were made by the wcf configuration wizard. 这些配置是由wcf配置向导完成的。

Any idea why the client project can't locate the host end point to retrieve the metadata ? 知道为什么客户端项目无法找到主机端点来检索元数据吗?

Thanks in advance. 提前致谢。

I had the same issue while revising an existing web odata service and then attempting to establish a new service reference to the revised service in a Silverlight project. 在修订现有的Web odata服务,然后尝试在Silverlight项目中建立对修订后的服务的新服务引用时,我遇到了同样的问题。 By temporarily commenting out the authentication and authorization sections in the web.config file I was able to connect to and download the metadata from the data service to my Silverlight project. 通过临时注释掉web.config文件中的身份验证和授权部分,我能够连接到元数据并将元数据从数据服务下载到我的Silverlight项目。 Rick Moulton 里克·莫尔顿

This is probably that the service is not running. 这可能是该服务未运行。

It could also be that port 8000 is blocked. 也可能是端口8000被阻止。

Edit: 编辑:

Based on your comment that the discover does not work within the same solution: This means that something is wrong with the project type. 根据您的评论,发现不适用于同一解决方案:这意味着项目类型有问题。

Thry to create a new WCF project, add the services you need, then copy over your existing code. 可以创建一个新的WCF项目,添加所需的服务,然后复制现有代码。

I was trying to do the same thing you were, adding a service reference only to run into a connection error because the current service wasn't running. 我试图做与您相同的事情,添加服务引用只是为了运行连接错误,因为当前服务未运行。

In order to pull this trick off, you need to open two Visual Studio Instances and use one to first Open the "Add Service Reference" Menu. 为了实现这一技巧,您需要打开两个Visual Studio实例,并首先使用一个实例打开“添加服务引用”菜单。 With the menu open, in your other Visual Studio, debug your application so that your service is running. 打开菜单,在其他Visual Studio中,调试应用程序,以便服务运行。

While the service is running enter the address in the "Add Service Reference" menu and it WILL find your URL listening service. 服务运行时,在“添加服务参考”菜单中输入地址,它将找到您的URL侦听服务。 Only then can you select the interface or class you wish to reference. 只有这样,您才能选择要引用的接口或类。

After that's done you can stop the debugging and the changes will take effect. 完成后,您可以停止调试,更改将生效。 You may get a warning that your project was modified outside the editor just click OK and you'll be good. 您可能会收到一条警告,说您的项目已在编辑器外部被修改,只需单击“确定”就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM