zoukankan      html  css  js  c++  java
  • 在WEBSERVICE学习中遇到的问题

    向我的WEBSERVICE发了一个这样的GET类的请求
    http://127.0.0.1/VegService.asmx/Getvegetable?vegetablename=cucumber
    然后得到报错
     

    “/”应用程序中的服务器错误。

    请求格式无法识别。

    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

    异常详细信息: System.InvalidOperationException: 请求格式无法识别。

    源错误:

    执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

    堆栈跟踪:

    [InvalidOperationException: 请求格式无法识别。]
       System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +388
       System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +94
       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
    


    版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573

    原webservice程序如下

    <%@ WebService Language="vb" Class="Vegetables.Vegservice"%>

    imports system
    imports system.web.services
    imports system.web.services.protocols
    imports system.xml

    namespace Vegetables


        
    <webservice(namespace:="http://hx66.com/net")>public class Vegservice
            inherits system.web.services.webservice

        
    public enum Appearance
            
    Round
            Bendy
            Odd
        
    end enum

        
    Public structure Vegetable
            
    public VegName as string
            
    public VegColor as string
            
    public VegLooks as Appearance
            
    public NumberInStock as integer
        
    end structure
            
    <webmethod()>Public function GetVegetable(byval vegetablename as stringas Vegetable
                
    'Context.request.saveas("c:\VegServiceRequest.htm",false)
                dim result as Vegetable

                
    select Case vegetablename.tolower()
                    
    case "cucumber"
                        result.VegName="Cucumber"
                        result.VegColor="Green"
                        result.VegLooks= Appearance.Bendy
                        result.NumberInStock
    =10
                    
    case "sweetcorn"
                        result.VegName="Sweetcorn"
                        result.VegColor="Yellow"
                        result.VegLooks= Appearance.Odd
                        result.NumberInStock
    =2
                    
    case "potato"
                        result.VegName="Potato"
                        result.VegColor="Brown"
                        result.VegLooks= Appearance.Round
                        result.NumberInStock
    =55
                    
    case else
                        
    dim code as xmlqualifiedname
                        code
    =new xmlqualifiedname("Sender","http://schemas.xmlsoap.org/soap/envelope")
                        
    dim doc as xmldocument
                        doc
    =new xmldocument()
                        
    dim detail as xmlelement
                        detail
    =doc.createelement("detail")
                        
    dim veg as xmlelement
                        veg
    =doc.createelement("vegFault","vegetableName","http://www.hx66.com/net/vegservice/faults")
                        veg.innertext
    =vegetablename
                        detail.Appendchild(veg)
                        doc.appendchild(detail)
                        throw 
    new soapexception("Unknown vegetable.",code,"http://www.hx66.com/net/vegservice",doc)
                
    end select
                return result
            
    end function

            
    <webmethod()>public function GetVegetables(byval vegetablenames as string()) as Vegetable()
                
    'context.request.Saveas("c:\VegServiceRequest.htm",false)
                dim results() as Vegetable
                results
    = new Vegetable(vegetablenames.length){}

                
    dim resultNum as integer
                
    for resultNum = 0 to results.length - 1 step resultNum + 1
                    results(resultNum)
    =GetVegetable(vegetablenames(resultNum))
                
    next

                return results
            
    end function
        
    end class
    end namespace    

    我在机器上是装了.net framework SDK的
    这种情况我也不知道是什么原因了
    好像是不接受GET方法
    直接在页面点击方法提交参数还是可以的。

    请高手帮帮忙!!!!
  • 相关阅读:
    Java实现 LeetCode 432 全 O(1) 的数据结构
    Java实现 LeetCode 432 全 O(1) 的数据结构
    Makefile 自动生成依赖
    比较详细的利用虚拟机对SD卡FAT32+EXT4+Ext4分区图解教程
    STM32F0308开发环境的选择--CooCox CoIDE篇
    linux下包管理命令yum与apt-get以及开发环境配置
    裸机编程与OS环境编程的有关思考
    Eclipse C/C++环境配置
    Linux Eclipse代码提示功能设置(Java & C/C++)
    Linux下高效编写Shell——shell特殊字符汇总
  • 原文地址:https://www.cnblogs.com/aowind/p/111310.html
Copyright © 2011-2022 走看看