简体   繁体   English

调用WCF服务端点

[英]Calling a WCF service endpoint

I have created a WCF service with an endpoint, hosted in IIS, with a .svc file. 我创建了一个WCF服务,其端点在IIS中托管,带有.svc文件。 When I hit the endpoint I get: 当我点击端点时,我得到:

在此输入图像描述

So it look like the end point is up. 所以看起来终点就好了。

I have created a Service Contract 我创建了服务合同

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

And created a class 并创建了一个类

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

How do I call the GetSearchResults method in the browser? 如何在浏览器中调用GetSearchResults方法?

Edit 编辑

The binding is: 绑定是:

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

You cannot test the result of the WCF service in browser. 您无法在浏览器中测试WCF服务的结果。 You can test it using the WCF Test client. 您可以使用WCF测试客户端对其进行测试。 In your IDE just open your .svc or .svc.cs file and then click F5 which should launch the WCF Test client. 在IDE中,只需打开.svc或.svc.cs文件,然后单击F5即可启动WCF测试客户端。

NOTE: Your project type is WCF Service Application Project 注意:您的项目类型是WCF服务应用程序项目

Also set the below in your web.config to enable metadata exchange. 还要在web.config中设置以下内容以启用元数据交换。

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

Why don't you just enable Service Metadata generation? 为什么不直接启用服务元数据生成? Once you have that, you can just right-click on your service in Visual Studio and select "Browse...". 完成后,您可以在Visual Studio中右键单击您的服务,然后选择“浏览...”。 VS will then open your browser to the right URL, and you can click the name of the method you want to execute. 然后,VS将打开您的浏览器到正确的URL,您可以单击要执行的方法的名称。 Then you'll see the correct URL to call your method, provided that HTTP GET is enabled (so you're not using SOAP). 然后,如果启用了HTTP GET(因此您不使用SOAP),您将看到调用方法的正确URL。

Otherwise, you'll have to use a WCF test environment such WCF Storm: http://www.wcfstorm.com/wcf/home.aspx 否则,您将不得不使用WCF测试环境,例如WCF Storm: http//www.wcfstorm.com/wcf/home.aspx

You can do it from the browser only if you are using webHttpBinding. 只有在使用webHttpBinding时才可以从浏览器执行此操作。 What you could do is use WcfTestClient tool it's located here: "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\WcfTestClient.exe" 你可以做的是使用它位于这里的WcfTestClient工具:“C:\\ Program Files(x86)\\ Microsoft Visual Studio 10.0 \\ Common7 \\ IDE \\ WcfTestClient.exe”

Also, your metadata is disabled, so in order to use WcfTestClient you will need to set httpGetEnabled to true in your webservice app.config 此外,您的元数据已禁用,因此为了使用WcfTestClient,您需要在webservice app.config中将httpGetEnabled设置为true。

The best is wcf storm . 最好的是wcf风暴 It's really powerful when it comes to test wcf. 在测试wcf时它真的很强大。

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

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