现在的位置: 首页 > 综合 > 正文

在WEBSERVICE学习中遇到的问题

2011年02月21日 ⁄ 综合 ⁄ 共 3876字 ⁄ 字号 评论关闭
向我的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方法
直接在页面点击方法提交参数还是可以的。

请高手帮帮忙!!!!

抱歉!评论已关闭.