我一直在阅读和阅读,但我越走越困惑。我正在用 C# 构建一个 ASP.NET 4.0 Web 应用程序。我正在尝试实施信用卡处理。我使用的公司提供了一个示例 XML SOAP 请求和响应,但我不知道该怎么做。我是一名新手开发人员,对这一切都很陌生。我只是不知道从哪里开始。非常感谢任何帮助,我也必须通过 SSL 发送,但这可能是另一个问题。
这是 SOAP 请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<v1:SendTranRequest xmlns:v1="http://postilion/realtime/merchantframework/xsd/v1/">
<v1:merc>
<v1:id>9000</v1:id>
<v1:regKey>RegistrationKey</v1:regKey>
<v1:inType>1</v1:inType>
<v1:prodType>5</v1:prodType>
</v1:merc>
<v1:tranCode>1</v1:tranCode>
<v1:card>
<v1:pan>411111******1111</v1:pan>
<v1:xprDt>1312</v1:xprDt>
</v1:card>
<v1:contact>
<v1:id>1234567</v1:id>
<v1:fullName>John Doe</v1:fullName>
<v1:coName>Ajax Intl.</v1:coName>
<v1:title>CEO</v1:title>
<v1:phone>
<v1:type>3</v1:type>
<v1:nr>5555555555</v1:nr>
</v1:phone>
<v1:addrLn1>123 1st St.</v1:addrLn1>
<v1:city>Somewhere</v1:city>
<v1:state>CO</v1:state>
<v1:zipCode>80021</v1:zipCode>
<v1:ctry>US</v1:ctry>
<v1:email>email@email.com</v1:email>
<v1:ship>
<v1:fullName>John Doe</v1:fullName>
<v1:addrLn1>123 1st St.</v1:addrLn1>
<v1:city>Somewhere</v1:city>
<v1:state>CO</v1:state>
<v1:zipCode>80021</v1:zipCode>
<v1:phone>5555555555</v1:phone>
<v1:email>email@email.com</v1:email>
</v1:ship>
</v1:contact>
<v1:reqAmt>099</v1:reqAmt>
<v1:usrDef>
<v1:name>firstname</v1:name>
<v1:val>John</v1:val>
</v1:usrDef>
<v1:indCode>1</v1:indCode>
<v1:tranFlags>
<v1:dupChkTmPrd>6000</v1:dupChkTmPrd>
<v1:convFeeAcptd>N</v1:convFeeAcptd>
</v1:tranFlags>
<v1:tax>
<v1:idcr>0</v1:idcr>
</v1:tax>
</v1:SendTranRequest>
</soapenv:Body>
</soapenv:Envelope>
这是我的创建请求和读取响应
WebRequest webRequest = WebRequest.Create("url");
HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Headers.Add("SOAPAction: http://tempuri.org/");
httpRequest.ProtocolVersion = HttpVersion.Version11;
httpRequest.Credentials = CredentialCache.DefaultCredentials;
//build xml
var xmlWriterSettings = new XmlWriterSettings
{
NewLineHandling = NewLineHandling.None,
Encoding = Encoding.ASCII
};
using (var requestStream = httpRequest.GetRequestStream())
using (var writer = XmlWriter.Create(requestStream, xmlWriterSettings))
{
xml.WriteTo(writer);
}
//Get the Response
HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse();
StreamReader srd = new StreamReader(wr.GetResponseStream());
string resulXmlFromWebService = srd.ReadToEnd();