添加WCF服务引用时出错?

时间:2016-07-27 10:16:05

标签: c wcf

我的WCF项目没问题,没有错误,我尝试浏览SVC文件,效果很好。 但是当我添加这个WCF引用时,它会抛出错误:

There was an error downloading 'http://MyIPAddress/BKKService/BService.svc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://MyIPAddress/BKKService/BService.svc'.
There was no endpoint listening at http://MyIPAddress/BKKService/BService.svc that could accept the message.

请帮我解决这个问题。

这是我的web.config文件

<services>
      <service name="BKKService.BService">
        <endpoint address="BKKService" binding="basicHttpBinding" 
                  bindingConfiguration="basicHttp" contract="BKKService.IBService"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://MyIPAddress/BKKService/BService.svc"/>
          </baseAddresses>
        </host>
      </service>
    </services>

1 个答案:

答案 0 :(得分:0)

您可以为与服务关联的每个端点指定绝对地址,也可以为服务的ServiceHost提供基址,然后为与此服务关联的每个端点指定相对于此基址定义的地址。
使用IIS托管时,您不自行管理ServiceHost实例。在IIS中托管时,基址始终是服务的.svc文件中指定的地址。因此,您必须为IIS托管的服务端点使用相对端点地址 因此“http://MyIPAddress/BKKService/BService.svc”不起作用,您需要使用.svc文件地址。如果使用IIS express,则在浏览svc文件时,添加服务引用的地址应为url。如果使用IIS,则它是在IIS中为.svc文件指定的地址。