更新时间:2022-05-25 10:14:34
假设您的requestMessage在您的其他帖子中相同(似乎是这种情况,因为错误消息表明它正在接收字符串),因此您使用了不正确的Message.CreateMessage重载.您使用的是
Assuming your requestMessage is the same in your other post (which seems to be the case, since the error message says it's receiving a string), you're using an incorrect overload of Message.CreateMessage. The one you're using is defined as
Message.CreateMessage(MessageVersion version, string action, object body);
您传递给它的请求消息"是整个消息信封.您正在使用的这个代码将尝试序列化主体(并且由于它是字符串,因此它将序列化为< string xmlns ="http://schemas.microsoft.com/2003/10/Serialization/"> ...</string>
-准确地映射到您的错误消息.
And the "request message" you're passing to it is the whole message envelope. This one you're using will try to serialize the body (and since it's a string, it will serialize it as <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">...</string>
- which maps exactly to the error message you have.
由于已经有了SOAP信封,因此需要使用的是一种重载方法,例如下面的方法:
What you need to use, since you already have the SOAP envelope, is one overload which takes that, such as the one below:
Message.CreateMessage(XmlReader enveloperReader, int maxSizeOfHeaders, MessageVersion version);
代码类似于:
string requestMessageString = @"<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:inf="http://www.informatica.com/"
xmlns:wsdl="http://www.informatica.com/wsdl/">
<soapenv:Header>
<inf:Security>
<UsernameToken>
<Username>john</Username>
<Password>jhgfsdjgfj</Password>
</UsernameToken>
</inf:Security>
</soapenv:Header>
<soapenv:Body>
<wsdl:doClient_ws_IbankRequest>
<wsdl:doClient_ws_IbankRequestElement>
<!--Optional:-->
<wsdl:Client_No>00460590</wsdl:Client_No>
</wsdl:doClient_ws_IbankRequestElement>
</wsdl:doClient_ws_IbankRequest>
</soapenv:Body>
</soapenv:Envelope>";
XmlReader envelopeReader = XmlReader.Create(new StringReader(requestMessageString));
Message requestMsg = Message.CreateMessage(envelopeReader, int.MaxValue, MessageVersion.Soap11);