从iOS调用WCF服务时会出现什么问题

时间:2014-10-23 06:19:39

标签: ios iphone wcf soap

发送给WCF服务的肥皂消息:

<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

<SOAP-ENV:Body>
  <ExecuteMobileEvent xmlns="http://address/2014/10">

  <sRequestStream>
    <?xml version="1.0"?>
    <Request>          
      <Params>            
        <LoginData UserId='abdul' Password='admin' UserType='D'/>            
      </Params>          
    </Request>        
  </sRequestStream>

  <lEventId>1000</lEventId>
  <lActorId>10</lActorId>
  <lClientId>1</lClientId>
  </ExecuteMobileEvent>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

对此肥皂信息的回复如下:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">
        a:DeserializationFailed
      </faultcode>
      <faultstring xml:lang="en-US">
        The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'ExecuteMobileEvent'. No characters can appear before the XML declaration. Line 9, position 18.
      </faultstring>
      <detail>
        <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <HelpLink i:nil="true"/>
          <InnerException>
            <HelpLink i:nil="true"/>
            <InnerException i:nil="true"/>
            <Message>
              No characters can appear before the XML declaration. Line 9, position 18.

任何人都可以找到问题所在吗?

1 个答案:

答案 0 :(得分:1)

删除邮件开头的空白。错误消息说得非常清楚:

  

在XML声明之前不会出现任何字符。

我非常确定这一点:

<?xml version="1.0"?>

也不属于第9行。

修复您的SOAP消息。

您是否真的计划在SOAP中通过未加密的渠道发送userId和纯文本密码?你应该真的找到一个知道如何做网络服务的人。