webmethod的参数类型可能用了非标准类型?

解决方案 »

  1.   

    我刚学WEB服务中只是把初始的HelloWorld方法前的注视去掉了,别的什么方法也没写
      

  2.   

    WebMethod]
    public string HelloWorld()
    {
    return "Hello World";
    }
      

  3.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Web;
    using System.Web.Services;namespace WebService1
    {
    /// <summary>
    /// Service1 的摘要说明。
    /// </summary>
    public class Service1 : System.Web.Services.WebService
    {
    public Service1()
    {
    //CODEGEN:该调用是 ASP.NET Web 服务设计器所必需的
    InitializeComponent();
    } #region Component Designer generated code

    //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 // WEB 服务示例
    // HelloWorld() 示例服务返回字符串 Hello World
    // 若要生成,请取消注释下列行,然后保存并生成项目
    // 若要测试此 Web 服务,请按 F5 键 [WebMethod]
    public string HelloWorld()
    {
    return "Hello World";
    }
    }
    }
      

  4.   

    这是在引用界面右边一栏出的
    <?xml version="1.0" encoding="utf-8" ?> 
    - <dynamicDiscovery xmlns="urn:schemas-dynamicdiscovery:disco.2000-03-17">
      <exclude path="_vti_cnf" /> 
      <exclude path="_vti_pvt" /> 
      <exclude path="_vti_log" /> 
      <exclude path="_vti_script" /> 
      <exclude path="_vti_txt" /> 
      <exclude path="Web References" /> 
      </dynamicDiscovery>
      

  5.   

    编译一次, 用浏览器查看一下asmx是否正常?
      

  6.   

    用浏览器查看一下asmx的第一页:
    Service1
    支持下列操作。有关正式定义,请查看服务说明。HelloWorld 
    --------------------------------------------------------------------------------此 Web 服务使用 http://tempuri.org/ 作为它的默认命名空间。
    建议:在使 XML Web service 公开之前,请更改默认命名空间。
    每个 XML Web service 都需要一个唯一的命名空间,以便客户端应用程序能够将它与 Web 上的其他服务区分开。http://tempuri.org/ 可用于正处于开发阶段的 XML Web services,而已发布的 XML Web services 则应使用更为永久的命名空间。应使用您控制的命名空间来标识 XML Web service。例如,可以使用您公司的 Internet 域名作为命名空间的一部分。尽管有许多 XML Web service 命名空间看似 URL,但它们不必指向 Web 上的实际资源。(XML Web service 命名空间为 URI。)对于用 ASP.NET 创建的 XML Web services,可以使用 WebService 特性的 Namespace 属性更改默认命名空间。WebService 特性是适用于包含 XML Web service 方法的类的特性。下面的代码实例将命名空间设置为“http://microsoft.com/webservices/”:C#[WebService(Namespace="http://microsoft.com/webservices/")]
    public class MyWebService {
        // 实现
    }
    Visual Basic.NET<WebService(Namespace:="http://microsoft.com/webservices/")> Public Class MyWebService
        ' 实现
    End Class
    有关 XML 命名空间的更多详细信息,请参阅 Namespaces in XML(XML 命名空间)上的 W3C 建议。有关 WSDL 的更多详细信息,请参阅 WSDL Specification(WSDL 规范)。有关 URI 的更多详细信息,请参阅 RFC 2396。
    调用HelloWorld 的方法产生第二页
    Service1
    单击此处以获得完整的操作列表。HelloWorld测试
    若要使用 HTTP GET 协议对操作进行测试,请单击“调用”按钮。 
      SOAP
    下面是一个 SOAP 请求和响应示例。所显示的占位符需要由实际值替换。POST /WebService1/Service1.asmx HTTP/1.1
    Host: localhost
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://tempuri.org/HelloWorld"<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <HelloWorld xmlns="http://tempuri.org/" />
      </soap:Body>
    </soap:Envelope>
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <HelloWorldResponse xmlns="http://tempuri.org/">
          <HelloWorldResult>string</HelloWorldResult>
        </HelloWorldResponse>
      </soap:Body>
    </soap:Envelope>
    HTTP GET
    下面是一个 HTTP GET 请求和响应示例。所显示的占位符需要由实际值替换。GET /WebService1/Service1.asmx/HelloWorld? HTTP/1.1
    Host: localhostHTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length<?xml version="1.0" encoding="utf-8"?>
    <string xmlns="http://tempuri.org/">string</string>
    HTTP POST
    下面是一个 HTTP POST 请求和响应示例。所显示的占位符需要由实际值替换。POST /WebService1/Service1.asmx/HelloWorld HTTP/1.1
    Host: localhost
    Content-Type: application/x-www-form-urlencoded
    Content-Length: length
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length<?xml version="1.0" encoding="utf-8"?>
    <string xmlns="http://tempuri.org/">string</string>产生的第三页:<?xml version="1.0" encoding="utf-8" ?> 
      <string xmlns="http://tempuri.org/">Hello World</string> 
    在此前我运行了Wsdl http://localhost/webservice1/webservece1.asmx?wsdl成功生成了
    webservece1.cs
      

  7.   

    看来是没有错了? 
    直接把代理类添加到项目中吧, 还要添加一个System.Web.WebService.dll
      

  8.   

    是不是在代理类中加入using System.Web.WebService.dll就可以调用了
    多多感谢
    回头给你加分,分虽不多但表示一下心情吧愿以后多多关照。
      

  9.   

    怎样将代理类添加到项目中,System.Web.WebService.dll放到哪,我将WebService1.dll,
    Service1.asmx,Service1.cs不行,把放到了C:\Inetpub\wwwroot\WebApplication1
    中一份,放到了C:\Inetpub\wwwroot\WebApplication1\bin中一份,不行;在WebApplication1.csproj用项目菜单下的填加类把把Service1.cs填加到webApplication1.csproj也不行总是出下面的错误提示:请在帮忙看看C:\Inetpub\wwwroot\WebApplication1\WebForm1.aspx.cs(11): 类型或命名空间名称“Services”在类或命名空间“System.Web”中不存在(是否缺少程序集引用?)
      

  10.   

    System.Web.WebService.dll是系统控件, 从项目->添加引用那直接选 
      

  11.   

    在作上面的工作前我已按你说的引用了(System.Web.WebService.dll是系统控件
    , 从项目->添加引用那直接选 )在程序中用下列语句调用Service1 myServece=new Service1();
    resultLabel.Text=myService.HelloWorld();产生下面的错误码
    感觉还是没能够把程序与web服务绑定

    C:\Inetpub\wwwroot\WebApplication1\WebForm1.aspx.cs(53): 找不到类型或命名空间名称“myq”(是否缺少 using 指令或程序集引用?)
    C:\Inetpub\wwwroot\WebApplication1\WebForm1.aspx.cs(52): 找不到类型或命名空间名称“Service1”(是否缺少 using 指令或程序集引用?)
      

  12.   

    问题解决了:我在WebApplication1中加入了一个类名子叫Service1.cs,
    然后把WebService中代理类Service1.cs的原码考到新建的Service1.cs类中替换原来的代码
    保存调试通过请问一下这样做有什么阴含的弊病吗,与填加Web引用有什么大的不同吗,以后我可以这样做吗?再次感谢!!!