我需要支持一堆仅限 SOAP 的服务,但我在定义服务时遇到了麻烦,即现有客户端可以使用这些服务而无需更改或几乎没有更改。我正在努力解决的问题是,1. 正确获取 POST 值,2. SOAPAction,3. 包括数据类型,以及 4. 让它包括所有子数据成员。
考虑这个搜索商店的简单服务:
- - 要求 - -
POST /services-1.0/Store.asmx
SOAPAction: http://example.com/Services/LookupStores
Content-Type: text/xml; charset=utf-8
Content-Length: string
Host: string
<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<LookupStores xmlns="http://example.com/Services">
<AuthenticationID>string</AuthenticationID>
<NameMatch>string</NameMatch>
</LookupStores>
</soap:Body>
</soap:Envelope>
- - 回复 - - -
HTTP/1.0 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: string
<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<LookupStoresResponse xmlns="http://example.com/Services">
<LookupStoresResult>
<StoreList>
<StoreData>
<Number>string</Number>
<Name>string</Name>
</StoreData>
<StoreData>
<Number>string</Number>
<Name>string</Name>
</StoreData>
</StoreList>
<ResponseCode>string</ResponseCode>
<ResponseMessage>string</ResponseMessage>
<ExtendedResponseMessage>string</ExtendedResponseMessage>
</LookupStoresResult>
</LookupStoresResponse>
</soap:Body>
</soap:Envelope>
希望模仿它的服务代码:
public class Store : Service
{
public LookupStoresResponse Post(LookupStores request)
{
return new LookupStoresResponse();
}
}
[DataContract(Namespace="http://example.com/Services")]
public class LookupStores
{
[DataMember]
string AuthenticationID { get { return ""; } set { } }
[DataMember]
string NameMatch;
}
[DataContract]
public class LookupStoresResponse
{
[DataMember]
List<StoreData> LookupStoresResult;
}
[DataContract]
public class LookupStoresResult
{
[DataMember]
List<StoreData> StoreList;
}
[DataContract]
public class StoreData
{
[DataMember]
string Number;
[DataMember]
string Name;
}
产量:
POST /soap11 HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: LookupStores
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<LookupStores xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://example.com/Services">
<AuthenticationID />
<NameMatch i:nil="true" />
</LookupStores>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<LookupStoresResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/EagleServices.Services">
<LookupStoresResult i:nil="true" />
</LookupStoresResponse>
</soap:Body>
</soap:Envelope>