I have a service reference defined in my project (created in vs2013) and the bindings in the AppConfig are defined thus;
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IERSAPIService" maxReceivedMessageSize="2147483647"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://staging.saffire-online.co.uk/ERSAPIService/ERSAPIService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IERSAPIService"
contract="ErsTestSite.IERSAPIService" name="BasicHttpBinding_IERSAPIService" />
</client>
</system.serviceModel>
Within this service reference there is a function:
Public Function salesXMLCheck(ByVal xmlString As String) As String Implements ErsTestSite.IERSAPIService.salesXMLCheck
Return MyBase.Channel.salesXMLCheck(xmlString)
End Function
If I pass the following string ('Hello') into that function it returns the following:
<?xml version="1.0" encoding="UTF-8"?>
<ers itemtype="Sales Note" doctype="RET" status="NAK" errorcode="E200 [XML Parse Error]" date="2015-06-10 08:02:42" />
Essentially the service has received my message, parsed it , realised it's not properly formatted xml and sent back a message to that effect. To my mind at least that suggests that I am at least connecting with the service successfully.
However if I then call this function again, but this time passing in some valid xml;
<?xml version="1.0" encoding="UTF-8"?>
<ers uname="apiuser" pword="apipassword" myAttribute="fooBar" anotherOfMyAttributes="123456">
<salesnote snType="S" action="INSERT" salesContractRef="" saleDate="20090807" auctionID="14" logBookNums="" landingDecNums="" vesselName="SEA ANGEL" vesselPln="TN103" vesselMasterOwner="ARRANBRAE LTD" landingDate1="20090807" landingDate2="" landingDate3="" countryOfLanding="GBR" landingPortCode="GBADR">
<salesline speciesCode="NEP" faoAreaCode="27" ZoneCode="VB1" disposalCode="HCN" freshnessCode="A" sizeCode="2" presentationCode="HEA" stateCode="FRE" numberOfFish="" weightKgs="52" value="765" currencyCode="GBP" withdrawnDestinationCode="OTH" buyerReg="201" salesContractRef="B4123"/>
<salesline speciesCode="WHB" faoAreaCode="27" ZoneCode="VB2" disposalCode="HCN" freshnessCode="A" sizeCode="3" presentationCode="GHT" stateCode="FRE" numberOfFish="" weightKgs="12" value="55" currencyCode="EUR" withdrawnDestinationCode="BOL" buyerReg="201" salesContractRef="TT45687"/>
<salesline speciesCode="JAD" faoAreaCode="27" ZoneCode="VIID" disposalCode="COV" freshnessCode="C" sizeCode="2" presentationCode="FIL" stateCode="FRE" numberOfFish="" weightKgs="300" value="330" currencyCode="GBP" withdrawnDestinationCode="GIF" buyerReg="201" salesContractRef="B5687"/>
</salesnote>
</ers>
I end up with a System.ServiceModel.FaultExceptio'1' giving me the additional message; @String must be exactly 1 character long'.
the error is thrown on the returnsEditor.text line in the function below;
Dim value As String = File.ReadAllText("C:\Users\Public\Documents\View to Learn\SNADD.xml")
Using ters As New ErsTestSite.ERSAPIServiceClient
ters.Open()
returnsEditor.Text = ters.salesXMLCheck(value)
ters.Close()
End Using
Clearly the service connection works or the same message would be thrown when I substitute 'Hello' as the parameter to the function, so why is this error being thrown when I try and submit valid xml?
EDIT
when I look closely at the stack trace I see the following:
at System.Convert.ToChar(String value, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Data.Linq.DBConvert.ChangeType(Object value, Type type)
at Read_FreshnessGrade(ObjectMaterializer`1 )
at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at ERSAPIService.Helper.SalesNoteHelper.SalesNoteCheck(XDocument xlowerDocument, XDocument xmlOutput, String rootName, String userId) in C:\Users\ravneet.sodhi\Desktop\ERSAPIService\ERSAPIService\Helper\SalesNoteHelper.cs:line 262
at ERSAPIService.Helper.SalesNoteHelper.salesXMLCheck(String xmlString) in C:\Users\ravneet.sodhi\Desktop\ERSAPIService\ERSAPIService\Helper\SalesNoteHelper.cs:line 71
at ERSAPIService.ERSAPIService.salesXMLCheck(String xmlString) in C:\Users\ravneet.sodhi\Desktop\ERSAPIService\ERSAPIService\ERSAPIService.svc.cs:line 1776
As I am most definitely not raveet.sodhi does this mean that the xml is actually being successfully passed to the other end but that there is an issue in the service there?
Yes, you called the service just fine.
It seems the service uses LINQ to SQL and somewhere uses a
Char
field where it should be aString
.