我在我的项目中定义了一个服务引用(在 vs2013 中创建),因此定义了 AppConfig 中的绑定;
<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>
在此服务参考中有一个功能:
Public Function salesXMLCheck(ByVal xmlString As String) As String Implements ErsTestSite.IERSAPIService.salesXMLCheck
Return MyBase.Channel.salesXMLCheck(xmlString)
End Function
如果我将以下字符串('Hello')传递给该函数,它将返回以下内容:
<?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" />
本质上,该服务已收到我的消息,对其进行解析,意识到它的 xml 格式不正确,并为此发回了一条消息。至少在我看来,这表明我至少成功地连接了该服务。
但是,如果我再次调用此函数,但这次传入一些有效的 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>
我最终得到一个 System.ServiceModel.FaultExceptio'1' 给我额外的信息;@String 必须正好是 1 个字符长'。
错误在下面函数的returnsEditor.text 行中抛出;
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
显然,服务连接有效,或者当我将“Hello”替换为函数的参数时会抛出相同的消息,那么为什么在我尝试提交有效的 xml 时会抛出这个错误?
编辑
当我仔细查看堆栈跟踪时,我看到以下内容:
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
因为我绝对不是 raveet.sodhi,这是否意味着 xml 实际上已成功传递到另一端,但那里的服务存在问题?