问题描述
我想通过提交如下的SOAP请求来进行Fedex Tracking API调用。 Fedex Web服务最佳实践表明,方法为 HTTP POST ,而 Content-Type 应为'text / xml'
我找不到任何相关代码示例。
我尝试使用以下代码。如果它是HttpPost方法,则不会进行调用。当我尝试使用HttpGet方法时,调用最少,并引发错误。
[Produces("application/json","application/xml")]
[Route("api/fedex")]
[ApiController]
public class FedexController : BaseController
{
private readonly IConfiguration _config;
public const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
public const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
public FedexController(IConfiguration config)
{
ServicePointManager.SecurityProtocol = Tls12;
_config = config;
}
[HttpGet]
[Route("GetFedexTrackingStatus/{trackingNumber}")]
public IActionResult GetFedexTrackingStatus(int trackingNumber)
{
try
{
string url = "https://wsbeta.fedex.com:443/web-services/track";
HttpClient client = new HttpClient();
string str1 = @"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:v16='http://fedex.com/ws/track/v16'>
<soapenv:Header/>
<soapenv:Body>
<v16:TrackRequest>
<v16:WebAuthenticationDetail>
<v16:UserCredential>
<v16:Key>XXXXXX</v16:Key>
<v16:Password>XXXXXX</v16:Password>
</v16:UserCredential>
</v16:WebAuthenticationDetail>
<v16:ClientDetail>
<v16:AccountNumber>XXXXXX</v16:AccountNumber>
<v16:MeterNumber>XXXXXX</v16:MeterNumber>
</v16:ClientDetail>
<v16:TransactionDetail>
<v16:CustomerTransactionId>TrackByNumber_v16</v16:CustomerTransactionId>
<v16:Localization>
<v16:LanguageCode>EN</v16:LanguageCode>
<v16:LocaleCode>US</v16:LocaleCode>
</v16:Localization>
</v16:TransactionDetail>
<v16:Version>
<v16:ServiceId>trck</v16:ServiceId>
<v16:Major>16</v16:Major>
<v16:Intermediate>0</v16:Intermediate>
<v16:Minor>0</v16:Minor>
</v16:Version>
<v16:SelectionDetails>
<v16:CarrierCode>FDXE</v16:CarrierCode>
<v16:PackageIdentifier>
<v16:Type>TRACKING_NUMBER_OR_DOORTAG</v16:Type>
<v16:Value>192221280879</v16:Value>
</v16:PackageIdentifier>
<v16:PagingDetail></v16:PagingDetail>
<v16:SecureSpodAccount/>
<v16:Destination>
</v16:Destination>
</v16:SelectionDetails>
</v16:TrackRequest>
</soapenv:Body>
</soapenv:Envelope>";
HttpContent content = new StringContent(str1,Encoding.UTF8,"text/xml");
var response = client.PostAsync(url,content);
var result = response.Result.Content.ReadAsstringAsync();
return StatusCode(200,result.Result);
}
catch (Exception ex)
{
return StatusCode(500,"Error");
}
}
}
它会引发错误,例如:
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring xml:lang=\"en\">Fault</faultstring><detail><cause>UnrecoverableClientError</cause><code>SchemaError</code><desc>validation failure for TrackRequest Error:cvc-complex-type.2.4.a: Invalid content was found starting with element 'v16:SecureSpodAccount'. One of '{\"http://fedex.com/ws/track/v16\":CustomerSpecifiedTimeOutValueInMilliseconds,\"http://fedex.com/ws/track/v16\":ResponseFormat}' is expected.</desc></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>"
有人进行过这些SOAPRequest调用吗?如何传递XML作为输入?
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)