私はあまりにも克服しようとしてきたが、理解できないように見えるイライラする問題を抱えています。
WCF の SOAP エンドポイントと REST エンドポイントの両方で公開しているサービスがあります。オブジェクト コードの重複を避けるために、2 つのサービス間でコントラクト オブジェクトを再利用したいと考えています。これらのサービスの簡単な例を以下に示します。
/*REST Implementation*/
[ServiceContract]
public interface ITestService
{
[OperationContract]
[WebInvoke]
TestResponse Test(TestRequest request);
[OperationContract]
[WebGet]
int GetTest(int testId);
}
/*SOAP Implementation*/
[ServiceContract]
public interface ITestService
{
[OperationContract]
[WebInvoke]
TestResponse Test(TestRequest request);
[OperationContract]
[WebInvoke]
int GetTest(GetTestRequest request);
}
[DataContract(Namespace="http://www.mysite.com/Test")]
public class TestRequest
{
[DataMember]
public int ID {get;set;}
[DataMember]
public InnerTestRequest InnerTestRequest {get;set;}
}
[DataContract(Namespace="http://www.mysite.com/Test")]
public class InnerTestRequest
{
[DataMember]
public int ID {get;set;}
}
問題私が直面している問題は、両方のエンドポイントのコントラクト ペイロードが同じ XML 構造 (SOAP エンドポイントの SOAP エンベロープ内) を使用するようにしたいということです。
たとえば、REST エンドポイントでTest(TestRequest リクエスト)を呼び出して、次の XML を送信したいと思います。
<TestRequest xmlns="http://www.mysite.com/Test">
<InnerTestRequest>
<ID>2</ID>
</InnerTestRequest>
<ID>4</ID>
</TestRequest>
SOAPエンドポイントの場合、次のものを送信できると予想されます。
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<TestRequest xmlns="http://www.mysite.com/Test">
<InnerTestRequest>
<ID>2</ID>
</InnerTestRequest>
<ID>4</ID>
</TestRequest>
</s:Body>
また、応答を同じコントラクト ペイロードで同じ形式にしたいと考えています。[MessageContractAttribute] を使用して名前空間を指定し、BodyStyle を BodyStyle.Bare に設定するなど、これを達成するために複数の方法を試しましたが、まだ次の 2 つの問題が発生しています。
1. The http://www.mysite.com/Test namespace does not trickle down to the members of its class.
2. SOAP requests "wrap" the contract, and it changes the structure of the XML.
REST用とSOAP用の2つの個別のDataContractを指定せずにこれを達成する最善の方法は何ですか?
事前に感謝