首页 文章

调用WCF服务 endpoints

提问于
浏览
1

我创建了一个WCF服务,其 endpoints 在IIS中托管,带有.svc文件 . 当我点击 endpoints 时,我得到:

enter image description here

所以看起来终点就好了 .

我创建了服务 Contract

[ServiceContract]
public interface ImyService
{
   [OperationContract]
   String GetSearchResults();
}

并创建了一个类

[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
public class myService : ImyService
{
    public String GetSearchResults()
    {
        return "Hello World";
    }
}

如何在浏览器中调用GetSearchResults方法?

Edit

绑定是:

<bindings>
  <basicHttpBinding>
    <binding name="customBasicHttpBinding">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Ntlm"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

4 回答

  • 1

    您无法在浏览器中测试WCF服务的结果 . 您可以使用WCF测试客户端对其进行测试 . 在IDE中,只需打开.svc或.svc.cs文件,然后单击F5即可启动WCF测试客户端 .

    注意:您的项目类型是WCF服务应用程序项目

    还要在web.config中设置以下内容以启用元数据交换 .

    <serviceBehaviors>
        <behavior>
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
    </serviceBehaviors>
    
  • 0

    为什么不直接启用服务元数据生成?完成后,您可以在Visual Studio中右键单击您的服务,然后选择“浏览...” . 然后,VS将打开您的浏览器到正确的URL,您可以单击要执行的方法的名称 . 然后,如果启用了HTTP GET(因此您不使用SOAP),您将看到调用方法的正确URL .

    否则,您将不得不使用WCF测试环境,例如WCF Storm:http://www.wcfstorm.com/wcf/home.aspx

  • 0

    最好的是wcf storm . 在测试wcf时它真的很强大 .

  • 3

    只有在使用webHttpBinding时才可以从浏览器执行此操作 . 你可以做的是使用它位于这里的WcfTestClient工具:“C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ WcfTestClient.exe”

    此外,您的元数据已禁用,因此为了使用WcfTestClient,您需要在webservice app.config中将httpGetEnabled设置为true .

相关问题