开发者

Invoke of ASMX webmethod fails with XMLException but works without an ASP.Net client

When I test my webservice from my development webserver (screen below) I click the INVOKE button and a new window opens, prompts for OPEN or SAVE, and the application associated with the filetype opens the file in the window.

Invoke of ASMX webmethod fails with XMLException but works without an ASP.Net client

Hoping this will work when the ColdFusion(CF) developers call the webmethod, I tried to simulate the CF test by adding a few lines of code into my .Net webclient to call the same webmethod:

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);
    }

Using this ASP.Net page as a caller, I get a very strange error (see below). Please note in the StackTrace where DownloadCF method is followed by the SoapHttpClientProtocol.Invoke method and the error. I don't see why one approach fails while the other Invoke works properly.

Server Error in '/sdkTrimFileServiceASMXclient' Application.

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 

-----EDIT/UPDATE: Session Info from Fiddler2 There is one session to get this started. Result code is 200. WebView tab in the response looks exactly like my webclient page. When the button is clicked, I get one and only one new session in Fiddler2 pasted here:

#   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           

What follows is a paste of the Raw request for that session (ugly but how else to tell it?): POST http://mdwdata/sdkTrimFileServiceASMXclient/launcher.aspx HTTP/1.1 Accept: 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, / Referer: http://mdwdata/sdkTrimFileServiceASMXclient/launcher.aspx Accept-Language: en-us User-Agent: Mozilla/4.0 (compatible; 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) Content-Type: multipart/form-data; boundary=---------------------------7db1e23703ae Accept-Encoding: gzip, deflate Host: mdwdata Content-Length: 2844 Connection: Keep-Alive 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--

The corresponding Response from that session from Fiddler2 is simply an HTML page with a bunch of styling followed by the Stack Trace from the XML exception (Data at the root level is invalid. Line 1, position 1.) The stack trace is in the original post above so won't repeat it here.

I have a theory about what could be wrong but I really hesitate in making my updated post any longer (I am thinking about opening new question and referencing this as background info). Suggestions?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜