测试 SOAP WCF Web 服务的 URL 是什么?

What's the URL to test a SOAP WCF web service?

我对 WCF SOAP 还很陌生。

已成功构建基本 REST(web api) 网络服务并通过 url 对其进行测试(例如 api/users/1 上的 GET 到 return 用户id = 1 来自数据库),我现在正在尝试使用 WCF SOAP Web 服务进行类似的操作。

我不想构建代理客户端。理想情况下,我只想在浏览器中或使用 Fiddler 进行测试。

这是 ABC(地址、绑定、合同)program.cs 代码:

    static void Main(string[] args)
    {
        // Step 1  Create a URI to serve as the base address.
        Uri baseAddress = new Uri("http://localhost:1234/WCFsoap");

        // Step 2 : Create ServiceHost (this will host the webservice)
        ServiceHost selfHost = new ServiceHost(typeof(UserLookupWebService), baseAddress);

        try
        {
            // Step 3 : Add a service endpoint.
            selfHost.AddServiceEndpoint(
                typeof(IUserLookup),        //Contract
                new BasicHttpBinding(),        //Binding
                "newapi");       //Address (relative to selfhost url)

例如:

如何在 UserLookupWebService class 中调用 findUser(int userId = 1) 方法?我可以通过浏览器或 Fiddler 执行此操作吗?

您可以使用 svcutil.exe 创建代理 class 并使用该代理 class 连接到您的服务:

svcutil http://localhost:1234/WCFsoap

或者使用任何 SOAP 测试工具:

我很喜欢Soap UI but you can use as well WCF Test client例如