我一直在从事一个使用 SOAP API 的项目。我获得了两个网址
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stor="http://www.centershift.com/STORE40/">
<soapenv:Header/>
<soapenv:Body>
<stor:GetSiteDetails>
<!--LookupUser_Request-->
<stor:LookupUser_Request>
<stor:Username>?</stor:Username>
<stor:Password>?</stor:Password>
<stor:Channel>?</stor:Channel>
</stor:LookupUser_Request>
<stor:Request>
<stor:SiteID>
<stor:long>?</stor:long>
</stor:SiteID>
</stor:Request>
</stor:GetSiteDetails>
</soapenv:Body>
</soapenv:Envelope>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:stor="http://www.centershift.com/STORE40/">
<soap:Header/>
<soap:Body>
<stor:GetSiteUnitDataStatus>
<!--Optional:-->
<stor:Request>
<stor:SiteID>?</stor:SiteID>
</stor:Request>
</stor:GetSiteUnitDataStatus>
</soap:Body>
</soap:Envelope>
查看 1 页文档后文档链接。我发现它使用 WCF 进行服务和某种令牌身份验证。我尝试使用的服务是 GetSiteUnitDataStatus
还为服务GetSiteUnitDataStatus提供了示例代码。 链接
//Example
//We’ll assume you’ve got a web reference, let’s name it Store, in your Visual Studio project. At this point we need to reference our objects. We’ll need the standard service object, a GetSiteUnitDataStatus_Request request object. We can define and create those like this:
// Create a request and response objects
StoreServiceClient client = new StoreServiceClient();
GetSiteUnitDataStatus_Request request = new GetSiteUnitDataStatus_Request();
As with every method we need to pass in credentials. We also set up the parameters for our request.
client.ChannelFactory.Credentials.UserName.UserName = "user";
client.ChannelFactory.Credentials.UserName.Password = "pass";
client.ChannelFactory.Credentials.SupportInteractive = true;
request.SiteID = 123456;
//Finally we can call the method and pass across the login object and the request object to retrieve the data. It’s a good idea to do this in a Try Catch block.
try
{
// Call the method that will load the response object
UnitTypeStatus[] resp;
resp = client.GetSiteUnitDataStatus(request);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
//Note that if something goes wrong the service will respond with an exception. You’ll want to take a look at that message returned in that exception so it can be debugged.
关于使用 WCF 的 SOAP API 的教程或博客并不多。
我将非常感谢任何帮助我走上正确道路的帮助。
我的代码:
import requests
import xml.etree.ElementTree as ET
import pandas as pd
from zeep import Client
from zeep.helpers import serialize_object
import base64
# SOAP request URL
USERNAME='**********'
PASSWORD='**********'
ORG_ID = 999999
SITE_ID = 9999999999999999
WSDL_URL = "https://slc.centershift.com/store40/StoreService.svc?wsdl"
# Create a Zeep client
client = Client(wsdl=WSDL_URL)
总的来说,Python 有 3 个用于调用 SOAP 服务的库:suds、suds-jurko 和 zeep。
SUDS是Python 2的库,Python 3安装大概率报错
suds-jurko 是一个用于解决 suds 错误的新库。
所以这里我首先建议你尝试一下使用suds库是否可以解决问题。
对于许多用例来说,SOAP 规范非常糟糕且不明确。这导致许多(较旧的)SOAP 服务器无法正确实现规范(或者以 Zeep 没有预料到的方式实现它们)。
所以我认为这篇文档可以帮助你。 错误报告