System.ServiceModel.FaultException'1'已修改

System.ServiceModel.FaultException'1' revised

我在我的项目中定义了一个服务引用(在 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') 传递到该函数中,它 returns 如下:

<?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 实际上已成功传递到另一端,但那里的服务存在问题?

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?

是的,您调用的服务很好。

似乎该服务使用 LINQ to SQL 并且某处使用 Char 字段,而它应该是 String.