使用XMLException调用ASMX webmethod失败但在没有ASP.Net客户端的情况下运行

时间:2011-09-08 20:08:58

标签: web-services asmx localhost httpcontext xmlexception

当我从我的开发网络服务器(下面的屏幕)测试我的web服务时,我单击INVOKE按钮并打开一个新窗口,提示OPEN或SAVE,与文件类型关联的应用程序在窗口中打开文件。

Localhost testing of webmethod

希望这可以在ColdFusion(CF)开发人员调用web方法时使用,我试图通过在我的.Net webclient中添加几行代码来模拟CF测试来调用相同的web方法:

protected void DownloadButton3_Click(object sender, EventArgs e)
    {
        string r = txtRecordNumber.Text;
        DownloadCF(r);
    }
    private void DownloadCF(string recNumber)
    {
        string fakeURLparm = txtFakeURLParm.Text;
        brokerService.Timeout = 9999999;
        brokerService.Credentials = System.Net.CredentialCache.DefaultCredentials;
        brokerService.DownloadFileCF(fakeURLparm, recNumber);
    }

使用这个ASP.Net页面作为调用者,我得到一个非常奇怪的错误(见下文)。请注意在StackTrace中,其中DownloadCF方法后面是SoapHttpClientProtocol.Invoke方法和错误。我不明白为什么一种方法失败而另一种Invoke正常工作。

'/ sdkTrimFileServiceASMXclient'应用程序中的

服务器错误。

Data at the root level is invalid. Line 1, position 1. 
Description: An unhandled exception occurred during the execution of the current web request.       Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.

Source Error: 


Line 231:        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://cbmiweb.com/sdkTrimFileServiceASMX/DownloadFileCF", RequestNamespace="http://cbmiweb.com/sdkTrimFileServiceASMX/", ResponseNamespace="http://cbmiweb.com/sdkTrimFileServiceASMX/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
Line 232:        public string DownloadFileCF(string trimURL, string TrimRecordNumber) {
Line 233:            object[] results = this.Invoke("DownloadFileCF", new object[] {
Line 234:                        trimURL,
Line 235:                        TrimRecordNumber});
Source File: C:\ProjectsVS2010\sdkTrimFileServiceASMX\FileServiceProxy\Web References\ASMXproxy\Reference.cs    Line: 233 
Stack Trace: 
[XmlException: Data at the root level is invalid. Line 1, position 1.]
   System.Xml.XmlTextReaderImpl.Throw(Exception e) +76
   System.Xml.XmlTextReaderImpl.Throw(String res, String arg) +126
   System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() +3975494
   System.Xml.XmlTextReaderImpl.ParseDocumentContent() +187
   System.Xml.XmlTextReaderImpl.Read() +151
   System.Xml.XmlTextReader.Read() +15
   System.Xml.XmlReader.MoveToContent() +64
   System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +502
   System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +204

[InvalidOperationException: Response is not well-formed XML.]
   System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +282
   FileServiceProxy.ASMXproxy.FileService.DownloadFileCF(String trimURL, String TrimRecordNumber) in C:\ProjectsVS2010\sdkTrimFileServiceASMX\FileServiceProxy\Web References\ASMXproxy\Reference.cs:233
   WebClient.launcher.DownloadCF(String recNumber) in C:\ProjectsVS2010\sdkTrimFileServiceASMX\WebClient\launcher.aspx.cs:368
   WebClient.launcher.DownloadButton3_Click(Object sender, EventArgs e) in C:\ProjectsVS2010\sdkTrimFileServiceASMX\WebClient\launcher.aspx.cs:360
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618 

-----编辑/更新:来自Fiddler2的会话信息 有一个会话来启动它。结果代码为200.响应中的WebView选项卡看起来与我的webclient页面完全相同。单击该按钮时,我在Fiddler2中只有一个新会话粘贴在此处:

#   Result  Protocol    Host    URL Body    Caching Content-Type    Process Comments    Custom  
8   500 HTTP    mdwdata /sdkTrimFileServiceASMXclient/launcher.aspx 8,167   private     text/html; charset=utf-8    iexplore:4400           

以下是该会话的Raw请求的粘贴(丑陋,但如何告诉它?):     POST http://mdwdata/sdkTrimFileServiceASMXclient/launcher.aspx HTTP / 1.1     接受:image / gif,image / jpeg,image / pjpeg,image / pjpeg,application / x-ms-application,application / x-ms-xbap,application / vnd.ms-xpsdocument,application / xaml + xml,application / vnd.ms-excel,application / vnd.ms-powerpoint,application / msword, /     推荐人:http://mdwdata/sdkTrimFileServiceASMXclient/launcher.aspx     接受语言:en-us     User-Agent:Mozilla / 4.0(兼容; MSIE 7.0; Windows NT 5.2; Trident / 4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022 ;. NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; InfoPath.3)     内容类型:multipart / form-data;边界= --------------------------- 7db1e23703ae     Accept-Encoding:gzip,deflate     主持人:mdwdata     内容长度:2844     连接:保持活力     Pragma:no-cache

-----------------------------7db1e23703ae
Content-Disposition: form-data; name="__EVENTTARGET"


-----------------------------7db1e23703ae
Content-Disposition: form-data; name="__EVENTARGUMENT"


-----------------------------7db1e23703ae
Content-Disposition: form-data; name="__LASTFOCUS"


-----------------------------7db1e23703ae
Content-Disposition: form-data; name="__VIEWSTATE"

/wEPDwULLTEzNzAzNDU3MjgPZBYCAgMPFgIeB2VuY3R5cGUFE211bHRpcGFydC9mb3JtLWRhdGEWAgIBDw8WAh4EVGV4dAUTV2ViQ2xpZW50IC0gMS4zLjguMGRkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBQpMb2dMaXN0Qm94GPOeMic5o+L85SmULO5z3yzNQcQ=
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="__PREVIOUSPAGE"

yXPNVTg4Wvj3GjytyxWv8KoyO3MLbzw51kYChzcsuxZx7IxumYcxmkwqQIAVLmSjaEaH0sfkMpmaEFPuQoLRia8YUKhPVhh5NxqSDzyGa4Y-LGkkCe5CJRK1Rm2TUnL7Mw3w4Q2
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="__EVENTVALIDATION"

/wEWEALh4p2SAQK6+/bUAgK5gaaMBQKskZf8CwLJ0JnWAwL99O3eCQKdnvCuBgLGrJLIBAKNmrGmBQKmiPS0AQKpssxKAsSb6t8KAt+EiPUEApi43CQCoqfWowgC/8zR1Ay0LlmsrFijDr0zW8kPfHiRkTNgYw==
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="txtURL"

http://MDWDATA/sdkTrimFileServiceASMX/
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="txtTrimDBID"

60
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="txtWorkGroupServerName"

GROUPER
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="txtWorkGroupServerPort"

1137
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="txtFakeURLParm"

60~GROUPER~1137
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="txtTrimRecordType"

Document
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="txtOptionalMetaData"

udf:Agency=MACTE~udf:Grant Number=0102030405
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="FileUpload1"; filename=""
Content-Type: application/octet-stream


-----------------------------7db1e23703ae
Content-Disposition: form-data; name="txtRecordNumber"

5
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="DownloadButton3"

DownloadFileCF webmethod to HTTPContext.Current
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="txtCFSearchString"

sm_fulltext=google&sm_fulltext=docs&bool=and&sm_udf5=macte&sm_udf14=f&sortd1=rs_dateregistered&count&rows=50
-----------------------------7db1e23703ae
Content-Disposition: form-data; name="txtMultiLine"

User Name: CBMIWEB\johna
 Token: 988
 Authenticated: Kerberos
 System: False
 Guest: False
 Anonymous: False

-----------------------------7db1e23703ae--

来自Fiddler2的该会话的相应响应只是一个HTML页面,其中包含一系列样式,后跟XML异常的堆栈跟踪(根级别的数据无效。第1行,第1位。)堆栈跟踪在上面的原始帖子中,所以这里不再重复。

我有一个关于可能出错的理论,但我真的犹豫再次发布我的更新帖子(我正在考虑打开新问题并将其作为背景信息引用)。建议?

0 个答案:

没有答案