简体   繁体   English

在ASP.NET MVC应用中添加WCF服务引用失败

[英]Adding WCF service reference in ASP.NET MVC app fails

I'm trying to add a WCF service to my ASP.NET MVC application. 我正在尝试将WCF服务添加到我的ASP.NET MVC应用程序中。 After setting it up, I get an error whenever I want to test it. 设置好之后,每当要测试时都会收到错误消息。

Here is my code: 这是我的代码:

BackgroundTask.svc BackgroundTask.svc

public class BackgroundTask : IBackgroundTask
{
    public void ShutdownVm()
    {
    }

    public void UpdateTable()
    {
    }
}

IBackgroundTask.cs IBackgroundTask.cs

[ServiceContract]
public interface IBackgroundTask
{
    [OperationContract]
    void ShutdownVm();
    [OperationContract]
    void UpdateTable();
}

Web.config Web.config文件

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="bgtBehaviour" name="IsolutionsAzureManager.Controllers.BackgroundTask">
        <endpoint address="BackgroundTask" binding="basicHttpBinding"
          bindingConfiguration="" name="" contract="IsolutionsAzureManager.Controllers.IBackgroundTask" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:44304/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="bgtBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

So, whenever I want to test my WFC service, I get this error: Error: Cannot obtain Metadata from https://localhost:44304/Controllers/BackgroundTask.svc 因此,每当我要测试WFC服务时,都会出现此错误:错误:无法从https://localhost:44304/Controllers/BackgroundTask.svc获取元数据

Error: The HTML document does not contain Web service discovery information. 错误:HTML文档不包含Web服务发现信息。

Can anyone see the mistake? 谁能看到错误?

Because you are attempting to acquire the mex endpoint over Https, you'll also need to switch to mexHttpsBinding and to enable the httpsGetEnabled setting: 因为您尝试通过Https获取mex端点,所以还需要切换到mexHttpsBinding并启用httpsGetEnabled设置:

 <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />

Alternatively, obtain the endpoint via http ( http://localhost:44304/Controllers/BackgroundTask.svc ) and then just switch back to https once the client has built the service reference artifacts. 另外,也可以通过http( http://localhost:44304/Controllers/BackgroundTask.svc )获取端点,然后在客户端构建了服务引用工件后,立即切换回https。

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

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