Problems with a web service call
-
Friday, April 01, 2011 12:03 PM
Originally posted in the vb forum but was told to try here. Hope someone can help.
I am having trouble making a call to a 3rd party web service. The call works fine when a limited number of patients are included in the xml but if I increase to around 20 patients I get this error:
"The underlying connection was closed: The connection was closed unexpectedly."
I'm using this code:
Dim client As System.Net.WebClient = New System.Net.WebClient()
strResponse = client.DownloadString(Url & Msg)my url : https://engine.drfirst.com/servlet/rcopia.servlet.EngineServlet
my xml: <RCExtRequest version='1.8'><Caller><VendorName>vendorsc3412</VendorName><VendorPassword>accountsc3412</VendorPassword></Caller><RcopiaPracticeUsername>sc3412</RcopiaPracticeUsername><SystemName>vendorsc3412</SystemName><Request><Command>send_patient</Command><Synchronous>y</Synchronous><PatientList><Patient><ExternalID>1001</ExternalID><FirstName>John</FirstName><MiddleName>A</MiddleName><LastName>Doe</LastName><DOB>11/17/1945</DOB><Sex>M</Sex><Address1>121 W Main</Address1><Address2></Address2><City>South Boston</City><State>VA</State><Zip>24592</Zip><HomePhone>434-505-0000</HomePhone><SSN>123-45-6789</SSN></Patient></PatientList><CheckEligibility>n</CheckEligibility></Request></RCExtRequest>
This shows only one patient but I can include an unlimited number according to the webservice vendor. The xml is normally sent url encoded but not shown here.
I have also tried using this
Dim httpRequest As HttpWebRequest = HttpWebRequest.Create(Url)
httpRequest.Method = "POST"
httpRequest.ContentType = "text/xml"
Dim bytedata As Byte() = Encoding.UTF8.GetBytes(Msg)
httpRequest.ContentLength = bytedata.Length
Dim streamWriter As System.IO.Stream = httpRequest.GetRequestStream
streamWriter.Write(bytedata, 0, bytedata.Length)
StreamWriter.Close()
Dim httpWebResponse As System.Net.HttpWebResponse = httpRequest.GetResponse()
Dim streamReader = New System.IO.StreamReader(httpWebResponse.GetResponseStream())
Dim stringResult = StreamReader.ReadToEnd()
StreamReader.Close()This doesn't work at all. Returns unknown user.
FYI the xml is formed correctly. When placed in a browser it works as it should. (You can try it)
https://engine.drfirst.com/servlet/rcopia.servlet.EngineServlet?xml=<?xml version='1.0' encoding='UTF-8'?><RCExtRequest version='1.8'><Caller><VendorName>vendorsc3412</VendorName><VendorPassword>accountsc3412</VendorPassword></Caller><RcopiaPracticeUsername>sc3412</RcopiaPracticeUsername><SystemName>vendorsc3412</SystemName><Request><Command>send_patient</Command><Synchronous>y</Synchronous><PatientList><Patient><ExternalID>1001</ExternalID><FirstName>John</FirstName><MiddleName>A</MiddleName><LastName>Doe</LastName><DOB>11/17/1945</DOB><Sex>M</Sex><Address1>121 W Main</Address1><Address2></Address2><City>South Boston</City><State>VA</State><Zip>24592</Zip><HomePhone>434-505-0000</HomePhone><SSN>123-45-6789</SSN></Patient></PatientList><CheckEligibility>n</CheckEligibility></Request></RCExtRequest>
Also, if using an actual form with a submit button and a list of 20 patients it works fine. I just can't get it to work in code.
FYI this is an application and not a asp or web project.
Thanks,
Rut
All Replies
-
Friday, April 01, 2011 4:13 PMModerator
I'm sorry, but your question has nothing to do with ASMX web services.
The error you're getting probably means that the receiving service has a problem with your XML and simply can't tell you in a nice manner. For instance, maybe there is simply a limit on the number of patients you can include. Try sending the simplest patient data possible, and send 15 and see that it works, then keep increasing the number until it fails. If it always fails at the same number of patients, regardless of how complex each patient is, then it's probably a simple numeric limit.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
Friday, April 01, 2011 5:38 PM
Actually, the above sample contains only one patient and doesn't work with the above code. It does work pasted in a web browser.
So I'm assuming that there is some part of the message that doesn't belong in the code or I'm not coding it correctly.
-
Friday, April 01, 2011 8:00 PMModeratorHow are you generating the XML? If you are using StringBuilder or some other kind of string manipulation, then that may be your problem. You should be using one of the XML APIs in .NET, such as LINQ to XML or XmlDocument.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
Friday, April 01, 2011 8:50 PMAT this point I'm simply hardcoding the above xml into a string variable just to try to get it to work. Normally I'd use the xmldocument object
-
Saturday, April 02, 2011 6:04 PMModerator
You can't pass XML that way! You have to URL Encode it. You're passing an invalid query string!
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
Monday, April 04, 2011 3:10 PM
Ok. I understand that. I'm using the httputility.urlencode to encode the string. The web service vendor sent me a very simple form with a text area that contains the xml below and a submit button. It Posts to the above url. This works. The data is good. I'm just not understanding why, using the httpwebrequest object, I can't simulate this action.
Perhaps I'm still in the wrong forum for this?<?xml version='1.0' encoding='UTF-8'?><RCExtRequest version='1.8'><Caller><VendorName>vendorsc3412</VendorName><VendorPassword>accountsc3412</VendorPassword></Caller><RcopiaPracticeUsername>sc3412</RcopiaPracticeUsername><SystemName>vendorsc3412</SystemName><Request><Command>send_patient</Command><Synchronous>y</Synchronous><PatientList><Patient><ExternalID>1001</ExternalID><FirstName>John</FirstName><MiddleName>A</MiddleName><LastName>Doe</LastName><DOB>11/17/1945</DOB><Sex>M</Sex><Address1>121 W Main</Address1><Address2></Address2><City>South Boston</City><State>VA</State><Zip>24592</Zip><HomePhone>434-505-0000</HomePhone><SSN>123-45-6789</SSN></Patient></PatientList><CheckEligibility>n</CheckEligibility></Request></RCExtRequest>
-
Thursday, April 07, 2011 2:43 PM
first u try with soup UI tool. to test the webservice.
http://www.eviware.com/
u ill get free trail version.
-
Wednesday, June 20, 2012 1:56 AMdid you ever figure this out? I have the exact same problem now and I've tried all the recommended solutions, checked experts exchange and all that and still can't get it to work... a simple code example would be priceless.
-
Wednesday, June 20, 2012 2:00 AMIt's not SOAP, it's a simple POST method to a URL with the content type being xml. That's the problem, I actually wish it was SOAP.

