I have a asp.net web app with some in page web service methods. It is not an asmx page, just Default.aspx. For example:

    [WebMethod]
    public static string SignUp(UserCredential userCredential)
    {
    }

I have no problem consuming this web service using jquery embeded in the Default.aspx page. Now I want to consume this web method in a console program for example. When I add the web reference to the console program, it said: The HTML document does not contain Web service discovery information.

How can I consume this in page web service?

有帮助吗?

解决方案 2

You cannot consume that page method from outside of the page. You need a separate service for that.

You should do the following:

  1. Create a separate WCF service project to hold the new service
  2. Extract the guts of your page method into a similar service method in your new service project
  3. Test the new service and make it work
  4. In your ASP.NET project, use "Add Service Reference" to permit you to reference the new service
  5. Call the new service from inside of the page method

其他提示

Another option you have is to use the ASP.NET Web API to create your service methods and then consume them in a console application, like this:

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;

class Program
{
    static void Main(string[] args)
    {
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri("http://localhost:9000/");

        // Add an Accept header for JSON format.
        client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

        // Call Web API methods here
    }
}

Read Calling a Web API From a .NET Client for a tutorial on consuming an ASP.NET Web API service from a C# console application.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top