using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Runtime.InteropServices ; 
namespace WebService1
{
/// <summary>
/// Service1 的摘要说明。
/// </summary>
[WebServiceAttribute(Namespace="urn:schemas-syngress-com-soap")]
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
} #region 组件设计器生成的代码

//Web 服务设计器所必需的
private IContainer components = null;

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion 
[System.Web.Services.WebMethod]
public string HelloWorld(string input)
{
return input;
} [System.Web.Services.WebMethod]
public double AverageScore(double[]score)
{
double sum=0;
for(int i=0;i<=score.Length;i++ )
            sum+=score[i];
return sum/score.Length;  
}
}
}
//我在浏览器中输入
http://localhost/WebService1/Service1.asmx/HelloWorld?input=hello
总是提示:
请求格式无法识别。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 请求格式无法识别。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  大家帮帮忙

解决方案 »

  1.   

    webservice好像不能这样调用吧。
      

  2.   

    这样是不能够调用的你可以 在调用的地方
    先实例化这个webService,比如
    Service1 service=new Service1()service.HelloWorld("你好!");
      

  3.   

    whw123456说的我明白在实际使用时应该先引用Web服务
    然后调用。不过我现在测试都通不过。
    http://localhost/WebService1/Service1.asmx/echo?input=hello还是不好使!大哥们救救我!
      

  4.   

    foyuan(暴走零零漆) 我把其余的方法删掉
    就剩一下那一个方法 测试一下 
    还是不好使
      

  5.   

    我是哇哇的哭呀!没人帮咱没人帮唵[InvalidOperationException: 请求格式无法识别。]
       System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
       System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
       System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, String path, String pathTranslated, Boolean useAppConfig) +699
       System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +95
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +173 
      

  6.   

    从新添加一个webService 文件,设为起始页  然后测试~
      

  7.   

    http://localhost/WebService1/Service1.asmx