私の意図が何であるかをまず説明してから、私の質問に行きましょう。オブジェクトタイプからSOAPリクエストを作成するにはどうすればよいですか?
実行時にSOAPリクエストが多少不明なSOAPサービスと通信するシステムを構築しようとしています。最終的には、未知のオブジェクトからSOAPリクエストを生成する必要があります。適切な属性とプロパティを持つオブジェクトを最初から動的に作成し、それを私のサービスの "request"メソッドに渡してSOAPサービスに送信します。ここで私が作業していたコードと私が受け取っているエラーがあります。
SOAPクライアント:
/// <summary>
/// GOSService proxy class
/// </summary>
[DebuggerStepThroughAttribute()]
[DesignerCategoryAttribute("code")]
[WebServiceBindingAttribute(Name = "ServiceSoapBinding", Namespace = "service.domain.com", ConformsTo = WsiProfiles.None)]
[SoapRpcService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
public partial class TestService : SoapHttpClientProtocol
{
/// <summary>
/// Initializes a new instance of the TestService class.
/// </summary>
public TestService()
{
this.Url = "https://restsv01.domain.com/ServiceTest/services/TestService";
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnRemoteCertificateValidationCallback);
}
/// <summary>
/// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication.
/// </summary>
/// <param name="sender">An object that contains state information for this validation.</param>
/// <param name="certificate">The certificate used to authenticate the remote party.</param>
/// <param name="chain">The chain of certificate authorities associated with the remote certificate.</param>
/// <param name="sslPolicyErrors">One or more errors associated with the remote certificate.</param>
/// <returns>A Boolean value that determines whether the specified certificate is accepted for authentication.</returns>
private bool OnRemoteCertificateValidationCallback(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
/// <summary>
///
/// </summary>
/// <param name="order"></param>
/// <returns></returns>
[SoapRpcMethodAttribute("", RequestNamespace = "service.domain.com", ResponseNamespace = "service.domain.com")]
[SampleSoap.LoggerSoapExtensionAttribute]
[return: SoapElementAttribute("requestReturn")]
public object request(object parm)
{
object[] results = this.Invoke("request", new object[] { parm });
return ((object)(results[0]));
}}
テストモデル: (彼らは動的に生成され、任意の事前定義されたモデルがされませんが、テスト目的のために、私がテストするには、このモデルを使用しています。 )
[SerializableAttribute()]
[DebuggerStepThroughAttribute()]
[DesignerCategoryAttribute("code")]
[SoapTypeAttribute(Namespace = "http://entity.domain.com")]
public class ParentNode
{
private string nameField = "1";
[SoapElementAttribute(IsNullable = true)]
public string Name
{
get { return this.nameField; }
set { this.nameField = value; }
}
}
テスト通話コード:
Services.Soap.Models.ParentNode parent = new Services.Soap.Models.ParentNode();
parent.Name = "John Doe";
Services.Soap.TestService service = new Services.Soap.TestService();
object resp = service.request(parent);
私はこのコードを実行し、 n個のエラーがこの行で発生します。
object[] results = this.Invoke("request", new object[] { parm });
これはエラーです:
今The type Services.Soap.Models+ParentNode was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
私は強いタイプにサービス「リクエスト」メソッドのパラメータを変更した場合、要求は罰金構築し、 SOAPサービスに渡されます。
public object request(ParentNode parm)
私は、リクエストメソッドにパラメータとして型を渡すと、渡しするオブジェクトの「動的」インスタンスを作成するなど、この作業を取得するために、おそらく50の事を試してみました。
public object request(object parm, Type t)
{
dynamic converted = Convert.ChangeType(parm, t);
object[] results = this.Invoke("request", new object[] { converted });
return ((object)(results[0]));
}
「変換済み」は依然としてオブジェクト型とみなされたため、これは機能しませんでした。
"GetWriterForMessage"メソッドでソープエンベロープをインターセプトして自分のエンベロープを作成できるようにしましたが、それを利用できませんでした。
私の質問は、オブジェクトのパラメータ型を使ってSOAPリクエストを正常に構築するにはどうすればいいですか?私のアーキテクチャを正しく動作させるために取るべき別のアプローチがありますか?
コメントを回答に移動するだけです。下記参照。 – Namphibian