System.ServiceModel.FaultException' 1'修订

时间:2015-06-10 07:28:34

标签: vb.net wcf service-model

我的项目中定义了一个服务引用(在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

如果我将以下字符串(&#39; Hello&#39;)传递给该函数,则返回以下内容:

<?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&#39; 1&#39;给我额外的信息; @String必须正好长1个字符&#39;。

在下面的函数中的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

当我替换“你好”时,显然服务连接有效或者会抛出相同的消息。作为函数的参数,那么当我尝试提交有效的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实际上已成功传递到另一端但是服务中存在问题?

1 个答案:

答案 0 :(得分:1)

  

因为我绝对不是raveet.sodhi这是否意味着xml实际上已成功传递到另一端但是服务中存在问题?

是的,你打电话给服务就好了。

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